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

Open Source Technologies



                   Notes
                                                Use is one of the few statements that require no terminating semicolon,
                                                although you can give if you want.

                                 After you issue the use statement, sample_db is the default database:

                                 mysql>SELECT DATABASE();















                                 The other way to make a database current is to name it on command line during connection
                                 to the server as follows:

                                 % mysql -u subu -p sample_db
                                 The available databases could be viewed by issuing the command:

                                 mysql>SHOW DATABASES;
                                 14.2.5 Removing a Database

                                 You can remove it by the following query:

                                 mysql>drop database sample_db;

                                 The command will permanently remove the database.
                                 14.2.6 Creating Tables

                                 The CREATE TABLE statement allows you to create a table within the current database.

                                 Syntax for creating table:
                                 mysql>CREATE TABLE table_name(column_specs);

                                    •  table_name indicates the name you want to give the table.
                                    •  column_specs provides the specifications for the columns in the table, as well as indexes
                                      (if you have any).
                                 Each column specification in the create table statement consists of the column name, the type
                                 (like varchar, int, date, etc.) and possibly some column attributes.

                                                A table must have at least one column.  You cannot create a table without
                                                specifying any column name.


                                 Now we can create a table having name student and four fields having name as roll_no, name,
                                 specialization, dob(date of birth).




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