This statement is used to insert new records in a table.
SQL INSERT INTO Statement
The insert into statement is used to insert new record into the existing table.
Syntax:
There is two ways to insert data into the table:
Syn1:
[This form not specify the column names where the data will be inserted, only their values:]
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Syn2:
[This form specifies both the column names and the values to be inserted:]
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1, value2, value3, ...);
Below is existing "Student" table:
Example 1:
[we insert a new row(not specify only values) in "Student" table.]
The following statement are used as to insert a new record into the "Student" table:
INSERT INTO Student
VALUES ('Anuj','Ghaziabad','India')
Result:
Message Comes: (1 row(s) affected)
Note:
In above statement:
Did you notice, we did not insert any number into the ID field?
The ID column is automatically updated with a unique number for each record in the table.
Data Is Inserted Only in Specified Columns:
It is also possible to only insert data in specific columns.
The following statement will insert a new row, but only insert data in the "StudentName", "Address", and "Country" columns (and the ID field also be updated automatically).
Example 2:
[we insert a new row(specifies both the column names and the values) in "Student" table.]The following statement are used as to insert a new record into the "Student" table:
INSERT INTO Student (StudentName,Address,Country)
VALUES ('Rahul','Delhi','India')
Result:
Message Comes: (1 row(s) affected)
Conversion Conversion Emoticon Emoticon