-
Notifications
You must be signed in to change notification settings - Fork 13
Insert statement
Tako Lee edited this page Feb 16, 2014
·
24 revisions
-
Fit into one line if possible
INSERT INTO dbo.Points (PointValue) VALUES (CONVERT(Point, '3,4'));
-
Column list/value list fit into one line if possible
-
VALUES keyword left align with INSERT keyword
INSERT INTO MyLinkServer.AdventureWorks2008R2.HumanResources.Department (Name, GroupName) VALUES (N'Public Relations', N'Executive General and Administration');
-
VALUES keyword right align with INTO keyword
INSERT INTO MyLinkServer.AdventureWorks2008R2.HumanResources.Department (Name, GroupName) VALUES (N'Public Relations', N'Executive General and Administration');
-
-
Stacked column list
-
Comma at the end of line
INSERT INTO Sales.SalesHistory WITH (TABLOCK) (SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, ModifiedDate) SELECT * FROM Sales.SalesOrderDetail;
-
Comma at the begin of line
INSERT INTO Sales.SalesHistory WITH (TABLOCK) (SalesOrderID ,SalesOrderDetailID ,CarrierTrackingNumber ,ModifiedDate) SELECT * FROM Sales.SalesOrderDetail;
-
Comma at the begin of line, align columns
INSERT INTO Sales.SalesHistory WITH (TABLOCK) ( SalesOrderID ,SalesOrderDetailID ,CarrierTrackingNumber ,ModifiedDate) SELECT * FROM Sales.SalesOrderDetail;
-
Comma at the begin of line, align columns, space between comma and column is 1 or n
INSERT INTO Sales.SalesHistory WITH (TABLOCK) ( SalesOrderID , SalesOrderDetailID , CarrierTrackingNumber , ModifiedDate) SELECT * FROM Sales.SalesOrderDetail;
-
-
Stacked value list
-
Comma at the end of line
INSERT INTO Production.Location WITH (XLOCK)(Name, CostRate, Availability) VALUES (N'Final Inventory', 15.00, 80.00);
-
Comma at the begin of line
INSERT INTO Production.Location WITH (XLOCK)(Name, CostRate, Availability) VALUES (N'Final Inventory' ,15.00, ,80.00);
-
Comma at the begin of line, align columns
INSERT INTO Production.Location WITH (XLOCK)(Name, CostRate, Availability) VALUES ( N'Final Inventory' ,15.00, ,80.00);
-
Comma at the begin of line, align columns, space between comma and column is 1 or n
INSERT INTO Production.Location WITH (XLOCK)(Name, CostRate, Availability) VALUES ( N'Final Inventory' , 15.00, , 80.00);
-
-
Insert ... select, select statement indent from 0 to n
INSERT TOP (10) INTO HumanResources.NewEmployee SELECT e.BusinessEntityID, c.LastName, c.FirstName, pp.PhoneNumber, a.AddressLine1, a.City, sp.StateProvinceCode, a.PostalCode, e.CurrentFlag FROM HumanResources.Employee e INNER JOIN Person.BusinessEntityAddress AS bea ON e.BusinessEntityID = bea.BusinessEntityID INNER JOIN Person.Address AS a ON bea.AddressID = a.AddressID INNER JOIN Person.PersonPhone AS pp ON e.BusinessEntityID = pp.BusinessEntityID INNER JOIN Person.StateProvince AS sp ON a.StateProvinceID = sp.StateProvinceID INNER JOIN Person.Person as c ON e.BusinessEntityID = c.BusinessEntityID;