Tuesday, 9 October 2012

INSERT STATEMENT





Using insert statement we can insert one or more records into a Table or View in a SQL server database.

Syntax:
  • Single record insertion:
Insert into <Table name> values (Value 1,Value 2, …, Value N)

Example:
INSERT INTO Sample_Table VALUES (101,'A','M');

  • Multiple records insertion:
Insert <Table name> values
(Value 1,Value 2, …, Value N),
(Value 1,Value 2, …, Value N),
.,
.,
.,
(Value 1,Value 2, …, Value N)

Example:
INSERT Sample_Table VALUES
(102,'B','F'),
(103,'C','M'),
(104,'D','M'),
(105,'E','F');

  • Inserting values into selected columns:

Syntax:
Insert into <Table name> (Column 1, Column 2, …, Column N)
Values (Value 1, Value 2, …., Value N)

Example:
INSERT INTO Sample_Table (ID,Name,Gender) VALUES (106,'G','M')

No comments:

Post a Comment