INSERT. . . SELECT constants : Insert into select « Insert Delete Update « SQL Server / T-SQL Tutorial






5>
6>
7> CREATE TABLE Customers (
8>      CustomerID nchar (5) NOT NULL ,
9>      CompanyName nvarchar (40) NOT NULL ,
10>     ContactName nvarchar (30) NULL ,
11>     ContactTitle nvarchar (30) NULL ,
12>     Address nvarchar (60) NULL ,
13>     City nvarchar (15) NULL ,
14>     Region nvarchar (15) NULL ,
15>     PostalCode nvarchar (10) NULL ,
16>     Country nvarchar (15) NULL ,
17>     Phone nvarchar (24) NULL ,
18>     Fax nvarchar (24) NULL
19> )
20> GO
1>
2>
3> INSERT INTO Customers (CustomerID, CompanyName) SELECT '1', 'Bam Bam'
4> GO

(1 rows affected)
1>
2> select * from Customers;
3> GO
CustomerID CompanyName                              ContactName                    ContactTitle                   Address                                                      City            Region
       PostalCode Country         Phone                    Fax
---------- ---------------------------------------- ------------------------------ ------------------------------ ------------------------------------------------------------ --------------- ---------
------ ---------- --------------- ------------------------ ------------------------
1          Bam Bam                                  NULL                           NULL                           NULL                                                         NULL            NULL
       NULL       NULL            NULL                     NULL

(1 rows affected)
1>
2> drop table Customers;
3> GO








2.2.Insert into select
2.2.1.The syntax of the INSERT statement for inserting rows selected from another table
2.2.2.INSERT. . . SELECT constants
2.2.3.INSERT statement with a column list and select clause
2.2.4.Use insert...into...select in a stored procedure
2.2.5.Inserting Rows from Another Table