Page 240 - Open Soource Technologies 304.indd
P. 240

Unit 14: Connecting to MySQL with PHP



            The CREATE TABLE statement for the student table look like this                       Notes

            mysql>CREATE TABLE student
                        (

                        roll_no  INT  UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                        name VARCHAR(20) NOT NULL,

                        specialization VARCHAR(6) NOT NULL,

                        dob DATE NOT NULL);
            In the above insert statement:

               •  INT signifies that the column holds integers (value with no fractional part).
               •  UNSIGNED disallows negative numbers.

               •  NOT NULL means that the column value must be filled in. (No student can be without
                 a roll number).

               •  AUTO_INCREMENT  works  like  this:  If the value for the roll_no column is missing
                 (or NULL) when you create a new student table record, MySQL automatically generates
                 a unique number that is one greater than the maximum value currently in the column.

               •  PRIMARY KEY means each value in the column must be unique. This prevents us for using
                 the roll number twice by mistake, which is desirable property for student roll number.
                 (Not only that, but MySQL requires every AUTO_INCREMENT column have a unique
                 index).
               •  VARCHAR(n)  means  the  column  contains  variable-length  character  values,  with  a
                 maximum length of n characters.
               •  Column  type  DATE  holds  the  value  in  the  format  “YYYY-MM-DD”(for  example,”
                 1983-10-24”)

































                                             LOVELY PROFESSIONAL UNIVERSITY                                   235
   235   236   237   238   239   240   241   242   243   244   245