Page 263 - Information_Practice_Fliipbook_Class11
P. 263

Alternatively,  CHECK constraints may be may be described separately as a table level constraints, after  all, attributes
            are described, for example:

            CREATE TABLE EMPLOYEE (
            ID INT PRIMARY KEY,
            FName VARCHAR(20) NOT NULL,
            LName VARCHAR(20) NOT NULL,

            Gender CHAR(1) NOT NULL,
            Address VARCHAR(30),
            City VARCHAR(20),
            Pin_Code CHAR(6),
            DOB DATE,
            Salary INT NOT NULL,

            Dept_No SMALLINT,
            CHECK(Gender = 'M' OR Gender = 'F' OR Gender='O'),
            CHECK(Salary BETWEEN 8000 AND 100000)
            );#EMPLOYEE

            9.5.3 Describe Table
            The SQL statement DESCRIBE (or DESC in short) is used to show the structure of a database table. The syntax of the
            DESCRIBE statement is as follows:

            DESCRIBE table_name;
            or

            DESC table_name;
            On executing the statement:

            DESCRIBE EMPLOYEE;
            SQL will respond as follows:
                                                Table 9.2: Result of DESCRIBE statement
                                   +----------+-------------+----------+--------+------------+---------+
                                   | Field    | Type        | Null     | Key    | Default    | Extra   |
                                   +----------+-------------+----------+--------+------------+---------+
                                   | ID       | int(11)     | NO       | PRI    | NULL       |         |
                                   | FName    | varchar(20) | NO       |        | NULL       |         |
                                   | LName    | varchar(20) | NO       |        | NULL       |         |
                                   | Gender   | char(1)     | NO       |        | NULL       |         |
                                   | Address  | varchar(30) | YES      |        | NULL       |         |
                                   | City     | varchar(20) | YES      |        | NULL       |         |
                                   | Pin_Code | char(6)     | YES      |        | NULL       |         |
                                   | DOB      | date        | YES      |        | NULL       |         |
                                   | Salary   | int(11)     | NO       |        | NULL       |         |
                                   | Dept_No  | smallint(6) | YES      |        | NULL       |         |
                                   +----------+-------------+----------+--------+------------+---------+

            9.5.4 SHOW TABLES statement

            Having created all the tables, we can use the following SQL statement to show the list of tables created in the database
            COMPANY as follows:

            SHOW TABLES;



                                                                Database Concepts and the Structured Query Language  249
   258   259   260   261   262   263   264   265   266   267   268