SQL Insert into statement
The INSERT INTO statement is used to insert a new record in a table.
we can insert records with two ways
1st way:
in this way we doesn't specify the column names where the data will be inserted, only their values:
INSERT INTO table_name
VALUES (value1, value2, value3,...)
VALUES (value1, value2, value3,...)
2nd Way
in this way we specify the column names where the data will be inserted
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
VALUES (value1, value2, value3,...)
The Example
INSERT into author
VALUES (4,'Java', 'Johan', 'what is java')
VALUES (4,'Java', 'Johan', 'what is java')
The "Tutorials" table will now look like this:
| ID | Category | Author | Tutorial |
| 1 | PHP | Hassan | what is php |
| 2 | MySql | James | what is sql |
| 3 | Ajax | Andrew | what is ajax |
| 4 | ASP | James | ASP Introduction |
| 5 | C++ | Andrew | C++ Basics |
| 6 | Java | John | what is java |
Insert Data Only in Specified Columns
INSERT INTO Persons (id, category, author)
VALUES (7, 'CSS', 'Williams')
VALUES (7, 'CSS', 'Williams')
The "Tutorials" table will now look like this:
| ID | Category | Author | Tutorial |
| 1 | PHP | Hassan | what is php |
| 2 | MySql | James | what is sql |
| 3 | Ajax | Andrew | what is ajax |
| 4 | ASP | James | ASP Introduction |
| 5 | C++ | Andrew | C++ Basics |
| 7 | CSS | Williams |