SQL INSERT QUERY
The SQL INSERT INTO Query is used to add new record of data to a table in the database.
There are two type of syntaxes of the INSERT INTO statement which are shown below.
The first way : Using data columns, here we write those column names in which we want to insert data.
syntax
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Example Query
INSERT INTO tbl_student_record (name ,class ,subject,city) VALUES ( 'Raju', '3rd', 'Math', 'Agra');
Before Query Execution : Table is empty.
id | name | class | subject | city | phone | fee | fee_date |
---|
After Query Execution : Table has one record.
Output
id | name | class | subject | city | phone | fee | fee_date |
---|---|---|---|---|---|---|---|
1 | Raju | 3rd | Math | Agra |
The Second way : Without using data columns, Here you can send the data in the same series in which you have placed data columns.
Syntax
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
Example Query
INSERT INTO tbl_student_record VALUES (1, 'Raju', '3rd', 'Math', 'Agra','9876543210','800','2018-1-2');
Before Query Execution : Table is empty.
id | name | class | subject | city | phone | fee | fee_date |
---|
After Query Execution : Table has one record.
Output
id | name | class | subject | city | phone | fee | fee_date |
---|---|---|---|---|---|---|---|
1 | Raju | 3rd | Math | Agra | 9876543210 | 800 | 2018-1-2 |