I switch between Oracle and SQL Server occasionally, and often forget how to do some of the most trivial tasks in SQL Server. I want to manually insert a row of data into a SQL Server database table using SQL. What is the easiest way to do that?
For example, if I have a USERS table, with the columns of ID (number), FIRST_NAME, and LAST_NAME, what query do I use to insert a row into that table?
Also what syntax do I use if I want to insert multiple rows at a time?
To insert a single row of data:
To do an insert on specific columns (as opposed to all of them) you must specify the columns you want to update.
To insert multiple rows of data in SQL Server 2008 or later:
To insert multiple rows of data in earlier versions of SQL Server, use "UNION ALL" like so:
Note, the "INTO" keyword is optional in INSERT queries. Source and more advanced querying can be found here.
I hope this will help you
Create table :
Insert values into the table :
Here are 4 ways to insert data into a table.
Simple insertion when the table column sequence is known.
INSERT INTO Table1 VALUES (1,2,...)
Simple insertion into specified columns of the table.
INSERT INTO Table1(col2,col4) VALUES (1,2)
Bulk insertion when...
INSERT INTO Table1 {Column sequence} SELECT * FROM Table2
Bulk insertion of selected data into specified columns of Table2.
.