Page 172 - IT-802_class_12
P. 172

Address VARCHAR(50)

        );
        If we see the structure of the table STUDENT, the following output appears:
        +---------------+-------------+------+-----+---------+-------+
        | Field         | Type        | Null | Key | Default | Extra |
        +---------------+-------------+------+-----+---------+-------+
        | Roll_No       | int         | NO   |     | NULL    |       |
        | Name          | varchar(30) | yES  |     | NULL    |       |
        | Gender        | char(1)     | yES  |     | NULL    |       |
        | Date_of_Birth | date        | yES  |     | NULL    |       |
        | Address       | varchar(50) | yES  |     | NULL    |       |
        +---------------+-------------+------+-----+---------+-------+
        1.5.2 DEFAULT Constraints

        The DEFAULT constraint allows to set default value for a column. The default value set when the table was created is
        utilised if a user has not entered a value for a column. For example, if the marks for the practical examination have not
        been input, then by default the minimum marks of 17 are stored automatically for the practical examination.
        CREATE TABLE mARKS

        (
        Roll_No iNTEGER NOT NULL,
        Theory_marks iNTEGER,

        practical_marks iNTEGER DEFAULT 17
        );
        Now, if we see the structure of the table MARKS, the following output appears:
        +-----------------+------+------+-----+---------+-------+
        | Field           | Type | Null | Key | Default | Extra |
        +-----------------+------+------+-----+---------+-------+
        | Roll_No         | int  | NO   |     | NULL    |       |
        | Theory_marks    | int  | yES  |     | NULL    |       |
        | practical_marks | int  | yES  |     | 17      |       |
        +-----------------+------+------+-----+---------+-------+
        1.5.3 CHECK Constraints

        The CHECK constraint can be used to limit the value of an attribute to those that fall inside a certain range. For example,
        the marks of the theory examination of any student cannot be greater than 70.

        CREATE TABLE mARKS
        (
        Roll_No iNTEGER NOT NULL,

        Theory_marks iNTEGER CHECK (Theory_marks <= 70),
        practical_marks iNTEGER DEFAULT 17

        );
        The CHECK constraint can also be used to compare two columns within a table having same data type.

                     Notes

                    MySQL does not support CHECK constraint, although it will not give any error if you have a check
                    constraint in your table.




          170   Touchpad Information Technology-XII
   167   168   169   170   171   172   173   174   175   176   177