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

Open Source Technologies



                   Notes         mysql>ALTER TABLE student add marks int(3);
                                 Then the table structure becomes:






















                                 Using ALTER statement you can change the data type of a column and the name of an existing
                                 table.

                                 Syntax for changing the data types of a column.
                                 ALTER TABLE table_name MODIFY column_name type.

                                 or

                                 ALTER TABLE table_name CHANGE column_name new column_name type.

                                            The difference between MODIFY and CHANGE is that, in case of CHANGE
                                            you can change name of column which is not possible by using MODIFY that’s
                                            why change takes two names?


                                 Syntax for changing the table name:
                                 ALTER TABLE table_name RENAME AS new_table_name

                                 Using ALTER statement you can remove a column from a table:
                                 Syntax is:




















                                 ALTER TABLE table_name DROP COLUMN col_name;




        240                               LOVELY PROFESSIONAL UNIVERSITY
   240   241   242   243   244   245   246   247   248   249   250