Microsoft SQL Server 2012 Transact-SQL DML Reference SQL Server Books Online

Microsoft SQL Server 2012 Transact-SQL DML Reference SQL Server Books Online

Microsoft SQL Server 2012 Transact-SQL DML Reference SQL Server Books Online Summary: Data Manipulation Language (DML) is a vocabulary used to retrieve and work with data in SQL Server 2012. Use these statements to add, modify, query, or remove data from a SQL Server database. Category: Reference Applies to: SQL Server 2012 Source: SQL Server 2012 Books Online(link to source content) E-book publication date: May 2012 263 pages Copyright © 2012 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Contents Data Manipulation Language (DML) Statements .......................................................................... 3 BULK INSERT............................................................................................................................. 4 DELETE .................................................................................................................................... 16 FROM ....................................................................................................................................... 27 Hints ......................................................................................................................................... 43 Join Hints ............................................................................................................................... 43 Query Hints ............................................................................................................................ 45 Table Hints ............................................................................................................................ 58 INSERT..................................................................................................................................... 74 MERGE................................................................................................................................... 100 OPTION Clause ...................................................................................................................... 114 OUTPUT Clause ..................................................................................................................... 114 READTEXT ............................................................................................................................. 130 Search Condition ..................................................................................................................... 132 SELECT .................................................................................................................................. 137 SELECT Clause ................................................................................................................... 140 SELECT Examples .............................................................................................................. 143 FOR Clause ......................................................................................................................... 157 GROUP BY .......................................................................................................................... 163 HAVING ............................................................................................................................... 173 INTO Clause ........................................................................................................................ 174 ORDER BY Clause .............................................................................................................. 179 OVER Clause ...................................................................................................................... 190 Table Value Constructor .......................................................................................................... 201 TOP ........................................................................................................................................ 205 UPDATE ................................................................................................................................. 212 UPDATETEXT ........................................................................................................................ 240 WHERE .................................................................................................................................. 244 WITH common_table_expression ............................................................................................ 246 WRITETEXT ........................................................................................................................... 257 Transact-SQL Syntax Conventions .......................................................................................... 260 Data Manipulation Language (DML) Statements Data Manipulation Language (DML) is a vocabulary used to retrieve and work with data in SQL Server 2012. Use these statements to add, modify, query, or remove data from a SQL Server database. In This Section The following table lists the DML statements that SQL Server uses. BULK INSERT (Transact-SQL) SELECT (Transact-SQL) DELETE (Transact-SQL) UPDATE (Transact-SQL) INSERT (Transact-SQL) UPDATETEXT (Transact-SQL) MERGE (Transact-SQL) WRITETEXT (Transact-SQL) READTEXT (Transact-SQL) The following table lists the clauses that are used in multiple DML statements or clauses. Clause Can be used in these statements FROM (Transact-SQL) DELETE, SELECT, UPDATE Hints (Transact-SQL) DELETE, INSERT, SELECT, UPDATE OPTION Clause (Transact-SQL) DELETE, SELECT, UPDATE OUTPUT Clause (Transact-SQL) DELETE, INSERT, MERGE, UPDATE Search Condition (Transact-SQL) DELETE, MERGE, SELECT, UPDATE Table Value Constructor (Transact-SQL) FROM, INSERT, MERGE TOP (Transact-SQL) DELETE, INSERT, MERGE, SELECT, UPDATE WHERE (Transact-SQL) DELETE, SELECT, UPDATE WITH common_table_expression (Transact- DELETE, INSERT, MERGE, SELECT, SQL) UPDATE 3 BULK INSERT Imports a data file into a database table or view in a user-specified format. Transact-SQL Syntax Conventions Syntax BULK INSERT [ database_name. [ schema_name ] . | schema_name. ] [ table_name | view_name ] FROM 'data_file' [ WITH ( [ [ , ] BATCHSIZE =batch_size ] [ [ , ] CHECK_CONSTRAINTS ] [ [ , ] CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ] [ [ , ] DATAFILETYPE = { 'char' | 'native'| 'widechar' | 'widenative' } ] [ [ , ] FIELDTERMINATOR = 'field_terminator' ] [ [ , ] FIRSTROW = first_row ] [ [ , ] FIRE_TRIGGERS ] [ [ , ] FORMATFILE ='format_file_path' ] [ [ , ] KEEPIDENTITY ] [ [ , ] KEEPNULLS ] [ [ , ] KILOBYTES_PER_BATCH =kilobytes_per_batch ] [ [ , ] LASTROW =last_row ] [ [ , ] MAXERRORS =max_errors ] [ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ] [ [ , ] ROWS_PER_BATCH =rows_per_batch ] [ [ , ] ROWTERMINATOR ='row_terminator' ] [ [ , ] TABLOCK ] [ [ , ] ERRORFILE ='file_name' ] )] Arguments database_name Is the database name in which the specified table or view resides. If not specified, this is 4 the current database. schema_name Is the name of the table or view schema.schema_name is optional if the default schema for the user performing the bulk-import operation is schema of the specified table or view. If schema is not specified and the default schema of the user performing the bulk- import operation is different from the specified table or view, SQL Server returns an error message, and the bulk-import operation is canceled. table_name Is the name of the table or view to bulk import data into. Only views in which all columns refer to the same base table can be used. For more information about the restrictions for loading data into views, see INSERT (Transact-SQL). 'data_file' Is the full path of the data file that contains data to import into the specified table or view. BULK INSERT can import data from a disk (including network, floppy disk, hard disk, and so on). data_file must specify a valid path from the server on which SQL Server is running. If data_file is a remote file, specify the Universal Naming Convention (UNC) name. A UNC name has the form \\Systemname\ShareName\Path\FileName. For example, \\SystemX\DiskZ\Sales\update.txt. BATCHSIZE = batch_size Specifies the number of rows in a batch. Each batch is copied to the server as one transaction. If this fails, SQL Server commits or rolls back the transaction for every batch. By default, all data in the specified data file is one batch. For information about performance considerations, see "Remarks," later in this topic. CHECK_CONSTRAINTS Specifies that all constraints on the target table or

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    266 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us