Page 252 - PYTHON-12
P. 252

For example,

                 mysql>CREATE TABLE student

                 (      Rollno         integer         NOT NULL PRIMARY KEY,
                        Name           varchar(20)     NOT NULL,
                        Gender         char(1),

                        Marks          integer(11)
                        DOB            date );
                 Query OK, 0 rows affected (0.04 sec)


               For each column, a name and a datatype must be specified and the column name must be unique
               within the table definition. Column definitions are separated by comma. Upper case and lower case
               letters make no difference in column names; the only place where upper and lower case letters
               matter are string comparisons.
               5. Viewing a Table

               To verify that the table has been created, SHOW TABLES command is used.
               mysql> show tables;

               +------------------------+
               | Tables_in_school  |
               +------------------------+
               | student      |

               | fees        |
               +------------------------+

               2 rows in set (0.01 sec)

               6. Viewing a Table Structure

               To view a table structure, DESCRIBE or DESC command is used.
               Syntax: DESCRIBE <tablename>; or DESC <tablename>;
               For example,

               mysql> describe student;
               +----------------+--------------------+----------------+---------+----------------+----------------+

               | Field               | Type                     | Null                | Key      | Default          | Extra              |
               +----------------+--------------------+----------------+---------+----------------+----------------+
           Computer Science with Python–XII  12.22 | Name              | varchar(20)      | YES                 |               | NULL              |                          |
               | Rollno            | integer(11)       | YES                 |               | NULL              |                          |



               | Gender          | char(1)                | YES                 |               | NULL              |                          |
               | Marks            | number(11)      | YES                 |               | NULL              |                          |

               | DOB                | date                       | YES                 |               | NULL              |                          |
               +----------------+--------------------+----------------+---------+----------------+----------------+
               5 rows in set (0.02 sec)
   247   248   249   250   251   252   253   254   255   256   257