Skip to content
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);

Clone this wiki locally