Sunday, February 10, 2013

SQL INSERT INTO Statement Syntax and Example

SQL INSERT INTO Statement
The INSERT INTO statement is used to insert a new rows/records into a table.
Syntax:
It is possible to write the INSERT INTO statement in two forms:
In the first form we doesn't specify the column names where the data will be inserted, only their values.
INSERT INTO Table_name VALUES (value1, value2, value3,...)
In the second form we specifies both the column names and the values to be inserted:
INSERT INTO Table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)

Example:

First we have to create a table (EMP) as follows to Insert Data :
CREATE TABLE [dbo].[EMP](
[Emp_ID] [float] NULL,
[E_Name] [varchar](255) NULL,
[Job] [varchar](255) NULL,
[Dept_ID] [float] NULL,
[Salary] [float] NULL

GO
-------------------------------------------------------------------------------------
Criteria-I : To insert a new row in the "EMP" table.
We use the following SQL statement:
INSERT INTO EMP VALUES (1234,'Tamatam', 'Analyst',23,10000)
-------------------------------------------------------------------------------------
Criteria- II : To Insert Data Only in Specified Columns:
It is also possible to only add data in specific columns.The following SQL statement will add a new row, but only adds data in to the specific columns
INSERT INTO EMP (Emp_ID, E_Name) VALUES ( 2345,'Reddy' )

--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog