Page 241 - Open Soource Technologies 304.indd
P. 241
Open Source Technologies
Notes After creating a table you can see the structure of that table by DESC statement or SHOW
COLUMNS FROM table_name
i.e.
mysql>DESC student;
or
mysql>SHOW COLUMNS FROM student;
If you happen to forget the name of any tables inside your database, you
can see it by giving the following query:
mysql>SHOW TABLES;
You can create primary key by combining two or more fields during table creation
by the using the following query:
CREATE TABLE table_name (col1_name type NOT NULL, col2_name type NOT NULL,.....,
primary key (col1, col2)).
The two fields combining which you want to make a primary key cannot be NULL.
Here type signifies data type of the field.
14.2.7 Inserting Data into the Table
The INSERT INTO statement allows you to insert data into a table.
Syntax for insertion is:
mysql>INSERT INTO table_name values(value1,value2,....);
>table_name indicates the name of the table.
>value1,value2.... are the number of values same as the number of columns in the table _name
specified
If you want to insert values into few fields instead of whole record, you can achieve this by the
following query:
mysql>INSERT INTO table_name(col1,col2,col3) values(value1,value2,value3);
or
mysql>insert into table_name set col1=value1,col2=value2,col3=value3...
Any column not named in the set clause is assigned a default value.
Another method of loading records into a table is to read the data values directly from a file.
You can load records using load data statement.
236 LOVELY PROFESSIONAL UNIVERSITY