15
}
%>
</body>
</html>
Output:
BIG=80
21.(b)(ii) How will you create a table in MySQL? Give the example and explain.[5]
The CREATE TABLE statement is used to create a table in MySQL.
The table creation command requires:
Name of the table
Names of fields
Definitions for each field
Syntax
Create table table_name (column1 datatype, column2 datatype, column3 datatype,…);
The following example creates a table called "student" that contains four columns: name, regno, dept and
year:
Example
Create table student(name char(15), trgno number(5), dept char(25), year number(4));
Creating Records
The INSERT INTO statement is used to create new records in a table.
It is possible to write the INSERT INTO statement in two ways.
First method
The first way specifies both the column names and the values to be inserted. In this method, values for all
columns are need not to be given.
syntax
INSERT INTO tablename (column1, column2, column3) VALUES (value1, value2, value3);
Example:
INSERT INTO student (name, regno, dept) VALUES ('raja', 1542, 'EEE');
Here, out of four columns, only 3 values are given.
Second method:
In the second method, column names are not mentioned, but values for all columns should be given.
syntax
INSERT INTO table_name VALUES (value1, value2, value3, ...);
Example:
INSERT INTO student VALUES ('raja', 1542, 'EEE', 2016);
Here, values for all columns are given.
KEY PREPARED BY
V. LAVANYA
Part Time / Guest Lecturer
120, Government Polytechnic College,
Purasaiwakkam, Chennai – 12.