Insert Command - dotnet and db

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Wednesday, August 1, 2018

Insert Command



Insert command is used to append data into an existing table.

Syntax:
INSERT INTO <Tablename>(Col1,Col2,col3, etc..)
VALUES (val1,val2val3,etc...);

Example:

INSERT INTO EmployeeInfo(EmpName,EmpDept,EmpLevel,EmpAddress,EmpPhone,UserName,[Password],Email)
VALUES ('Sudhakar','Accounts',3,'Meerpet',8897998408,'Sudhakar','123','Sudhakar@gmail.com');


Inserting only values:
INSERT INTO EmployeeInfo VALUES (1,'Sudhakar',2,3,'Meerpet',8897998408,'Sudhakar','123','Sudhakar@gmail.com');

Inserting one table data into another table:

Syntax:
1)INSERT INTO <tablename1>
  SELECT * FROM <tablename2>

2)INSERT INTO <tablename1>(Col1,Col2,Col3,etc..)VALUES

  SELECT Col1,Col2,Col3,etc... FROM <tablename2>


Example:

1)INSERT INTO EmployeeInfo
  SELECT * FROM EmployeeInfo2

2)INSERT INTO EmployeeInfo(EmpName,EmpDept,EmpLevel)VALUES
  SELECT (EmpName,EmpDept,EmpLevel) FROM EmployeeInfo2

No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.