We use the Insert Into Statement to add data to a table. We can use the Insert Into Statement in a number of different ways.
You can see these uses in the sample script below.
First, we are creating a table:
1 2 3 4 5 | Use [TestDB] GO CREATE TABLE [dbo].[MyTable] (Name VARCHAR(25)) GO |
Now, We will insert a value into this table in fourth methods.
First Method For Insert Operation:
1 2 3 4 | USE [TestDB] GO INSERT INTO [dbo].[MyTable] ([Name]) VALUES ('Nurullah ÇAKIR') GO |
Second Method For Insert Operation:
1 2 3 4 | USE [TestDB] GO INSERT INTO [dbo].[MyTable] VALUES ('Nurullah ÇAKIR') GO |
Third Method For Insert Operation:
1 | INSERT INTO [dbo].[MyTable] VALUES ('Nurullah ÇAKIR'),('Faruk ERDEM') |
Fourth Method For Insert Operation:
In this method, we are inserting values from MyTable to MyTable2
1 2 3 4 5 6 | USE [TestDB] GO INSERT INTO [dbo].[MyTable2] Select [Name] from MyTable GO Select Name From MyTable Select Name From MyTable2 |