SQL INSERT QUERY - The Coding Shala
Home >> Learn SQL >> SQL INSERT Query
Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.
SQL INSERT INTO STATEMENT
SQL 'INSERT INTO' Statement is used to insert a new row of data into the table. There are two basic statements to insert a new row into the table. First is by specifying columns names in which we want to insert data. The second way, if we want to add values in all the columns then we don't need to specify column names.
SQL INSERT INTO Syntax
The following is SQL INSERT INTO syntax with specifying columns name -
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN);
We can use SQL INSERT INTO syntax without specifying columns names. In that case values for every column need to be inserted.
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
SQL INSERT INTO Examples -
We have created the 'Persons' Table that is currently empty. The following query will insert data into the table -
insert into Persons(PersonID, LastName, FirstName, Address, City) values(1, 'Saini', 'Akshay', 'A-101', 'Pune'); Output -- PersonID LastName FirstName Address City 1 Saini Akshay A-1 Pune
- We can write this query like this also -
insert into Persons values(1, 'last', 'first', 'A-101', 'Pune'); PersonID LastName FirstName Address City 1 Saini Akshay A-101 Pune 1 last first A-101 Pune
- If we want to insert into 'PersonID', and 'FirstName' then -
insert into Persons(PersonID, FirstName) values(2, 'Akshay'); PersonID LastName FirstName Address City 1 Saini Akshay A-101 Pune 1 last first A-101 Pune 2 null Akshay null null
Other Posts You May Like
Prev<< SQL DROP Table NEXT >>SQL SELECT Query
Comments
Post a Comment