Learn SQL : How to create DataBase in MySQL, Tables in MySQL database and How To Insert Data In The Database.


Learn SQL : How to create DataBase in MySQL, Tables in MySQL database and How To Insert Data In The Database.
 
HOW TO CREATE DATABASE:

Open your MySQL Command Line Client, If you enter the password during installation then it demand for the password on opening. Otherwise, screen look like this: 




How to create tables in mysql database

  • Firstly you need to create a database to hold all the tables.The syntax for creating database is:


                    CREATE DATABASE table_name;

 Example: CREATE DATABASE student;
  Your screen look like this:



How to write tables name in mysql database


  • Now, you need to tell your database to actually use the database you created by using:
                                     USE database;

Example: USE student;
Your screen look like this:
Example of mysql databse tables



HOW TO CREATE TABLE:

This is done with the help of this syntax:


                        CREATE TABLE table_name 
                          ( column name 1 datatype, column name 2                                 datatype
                            );

  Example: CREATE TABLE stu_data
                   ( student_name VARCHAR(20),
                     student_rollno. VARCHAR(10),
                     student_mobileno. VARCHAR(10)
                       );

To see the structure of the table use this syntax:


                                     DESC table_name;


Example: DESC stu_data;
The table is shown as:


Mysql table

HOW TO INSERT DATA IN THE TABLE:

The syntax of Insert data directly in the table is:


                         INSERT INTO table_name
                         ( col 1, col 2, col 3......col N)
                          VALUES
                         (val 1, val 2, val 3........val N);

 Example: INSERT INTO stu_data(student_name, student_rollno,                     student_mobileno) VALUES ('ABC', 1, 8945372531);



  • Character data are written in single quotes while there is no need to enter the numeric data in quotes.
  • DESC is only used to see the structure of the data and to see the content we use SELECT statement as:

                        SELECT * FROM table_name;


Example: SELECT * FROM stu_data;
Our data look like as:


Tables in mysql



Previous                                                                                    Next                                                                               

No comments:

Powered by Blogger.