Wednesday 20 February 2013

SQL Insert Command


SQL Insert

SQL Insert command is used to insert data into tables. Insert command will insert data in the shape of rows into our table.
SYNTAX:
INSERT INTO tablename (column1, column2, column3) VALUES (‘value1’, ‘value2’, ‘value3’)


EXAMPLE:
INSERT INTO ITEMS_SHAHID4
(ItemName, ItemPrice, ItemCat)
VALUES
(‘Tab2’, ‘19000’, ‘computers’)


DESCRIPTION:
For INSERTING DATA INTO TABLES. If a value to be inserted is for a character or datetime data type, it must be enclosed within single quotes. Numbers do not require single quotation.


Example of Insert Command for MSSQL Server
Insert into Product values
(
'Samsung S3',
'Mobile Phone',
'41000'
)

Copy Data from one table into another table

To copy data between two tables of the same structure use the following statement:
Insert into TableB (field1, field2) select field1, field2 from TableA

 

No comments:

Post a Comment