Thursday 25 April 2013

A Introduction to creating databases in SQL Command Line.

SQL(Structured Query Language) is a query language used for accessing, modifying and Adding new information in a database. 

 In this article, you will learn about how you can create a new database in MySQL command line and how you can fill the data in those database. There is step by step procedure for you so that you can easily learn the basics of creating a new database in SQL.

Note: use semicolon to seperate two commands or end a command. after writing a command press enter to perform a function.

STEP 1: Open MY SQL Command Line.

















STEP 2: Create a new database by typing 
CREATE DATABASE yourdatabasename; and press enter. I have used name mynew database in my case.
You can try any other name or maybe this same name too.
You can see Query OK, 1 row affected. It means that you have succesfully create a new database.
Next, we will use this database to add data into our database.

STEP3: Using this database by typing the command:
USE mynewdatabase;

STEP4: Now we will insert table in our database. I have created table name Books.
CREATE TABLE Books
(
Id int,
BookName varchar(255),
Price varchar(255),
code int
)
The Table is sucessfully created and after that we will add data to the newly created table named Books.

STEP 5: To add data we will use following command to add 3 rows in the table:
INSERT INTO Books
(
Id
,BookName
,Price
,code
)
VALUES
('1', 'a love', '255', '1013')
,('2', 'loss life', '260', '2035')
,('3', 'wonder flight', '283','5044');

In the Values we have defined all 3 rows, and we can preview our table by using:
SELECT* FROM Books ;

Here, we will use SELECT command to select all (*) data from our table and retrieve it.
Now you can see  a preview of table sourrounded by dotted boundary box.

I hope you understood this tutorial very nicely and will enjoy doing MySQL. I will be soon back with the new tutorial.

Thanks.






0 comments:

Post a Comment