Friday, January 27, 2012

SQL Server :- SQL INSERT INTO syntax

Hi dear fnds  welcome to know about sql insert into command :-

Its very easy follow  below note :-

The SQL INSERT INTO syntax has Two main use and the result of either of them is adding a new rows into the database table.
The first syntax and example form of the INSERT INTO SQL clause doesn't specify the column names where the data will be inserted, but just their values:
INSERT INTO Table1 VALUES (value1, value2, value3…)
insert into table2 values (1,'jaiverma','DBA')
The second form of the SQL INSERT INTO command, specifies both the columns and the values to be inserted in them:
INSERT INTO Table1 (Column1, Column2, Column3…)
VALUES (Value1, Value2, Value3…)
insert into table2 (employee_id, emp_name, emp_role)
As you might already have think, the number of the columns in the second INSERT INTO syntax form must match the number of values into the SQL statement; otherwise you will get an error.
If we want to insert a new row into our Address table, we are going to use one of the following Two SQL statements:

Database: Adventure Works
Schema: Person
Table: Address



VALUES (5, '1226 Shoe St.', 'India', 'Dehli',79,98011,'FBAFF93',

'1999-01-20 00:00:00.000')





VALUES (5, '1226 Shoe St.', 'India', 'Dehli',79,98011,'FBAFF93',

'1999-01-20 00:00:00.000')
The result of the execution of either of the 2 INSERT INTO SQL statements will be a new row added to our Address database table.
 If you want to enter data for just a some of the table columns, you’ll have to use the second syntax form of the SQL INSERT INTO clause, because the first form will produce an error if you haven’t supplied values for all columns.
To insert only the AddressID and Addressline1 columns, execute the following SQL statement:

address(AddressID,AddressLine1) VALUES (5, '1226 Shoe St.')

Like and Share to SQL Integrity Blog

No comments:

Post a Comment

Thank You !!!!