Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 135 - CodePilot V5.0 C8
P. 135

    .....

                     column_nameN data_type(size)
                     );

                     While creating a table in SQL, it is necessary to give a
                     data type for each field/column.

                     Let’s create a table named Students having StudentID,
                     FirstName,  LastName,  Age  and Grade  fields in the
                     School database.
                     You can create more tables in the database in a similar way.

                     SHOWING TABLES

                     To  view  the  list  of tables  in  a  database,  use  the  SHOW TABLES
                     command. The syntax is as follows:

                     SHOW TABLES;
                     This will display all tables in the ‘School’ database.

                         The SHOW TABLE command is used to
                         display information about the columns               Create a Books table with BookID, Title,
                         in a table. It provides the same details         Author and Price columns. Set BookID as the
                                    as DESCRIBE.
                                                                                        PRIMARY KEY.

                     VIEWING STRUCTURE OF A TABLE
                     To view the structure (schema) of an existing table, you can use the DESCRIBE or DESC command.

                     This shows the columns in the table, their data types and other details like Null, Key, Default and Extra.
                     The syntax to DESCRIBE command is as follows:

                     DESCRIBE table_name;
                     or

                     DESC table_name;
                     The command to view the structure of the Students table is as follows:

                                                                                                                      133
                                                                                              MySQL: My First Database

| 130 131 132 133 134 135 136 137 138 139 140 |