SQL statement-Data manipulation

Source: Internet
Author: User

SQL statement-Data manipulation

Changes in the data in the table are reaching, which can also result in changes to the data in the index. Therefore, if the query statement does not require an index, you should delete the useless index to improve efficiency.

One, insert statement

  1. Basic INSERT statement

Insert is used to enter data into a table with the following syntax structure:

Values (value 1, value 2,....)

We can also specify the columns for which you want to insert data:

Values (value 1, value 2,....)

The entire syntax structure is as follows:

    INSERT[TOP (<expression>) [PERCENT] ][Into]<tabular Object>[(<column list>)][OUTPUT <output clause>] {values (<data values[m...n | <table source> Span style= "color: #808080;" >| exec <prodecure| default values}        

Example:

VALUES (' America ')  

A new feature was added in SQL Server2008, allowing multiple lines to be inserted at once, separated by commas "," such as:

intovalues (' America '), (' UK ');       

  2. INSERT into ... SELECT statement

What to do when we need to use some data sources as insert data. Data sources such as:

      • Another table in the database
      • A completely different database on the same server
      • A class of queries or other data from another SQL Server
      • Same table

INSERT into ... The SELECT statement completes the ability to insert a block of data at a time. Its syntax structure is a combination of the INSERT statement and the SELECT statement syntax structure:

<table name>[<column list>]<SELECT statement>  

Example:

Declart@MyTabletable (SalesOrderID char (5insert into  @MyTable select Salesorderid,customerid from AdventureWorks2008.Sales.SalesOrderHeader  WHERE SalesOrderID between 44000 Span style= "color: #808080;" >and 44010;         
second, UPDATE statement

The UPDATE statement updates the data in the table with the simplest syntax structure:

= a value

The complete syntax structure is as follows:

UPDATE[TOP (<expression>)][PERCENT]<tabular Object>SET<Column> = <value> [[,<column> = <value> [. WRITE (<expression>),<offset>,<length>) ][output <source Table (s) >][where <restrictive condition>                 

BASIC syntax Structure:

<table name><column<value[,<column> = <value>][ From <source table (s) >][WHERE <restrictive condition>]   

Example:

' China 4 
Third, DELETE statement

The DELETE statement is used to delete data from the table, and the complete syntax structure of the DELETE statement is as follows:

DELETE[top (<expression>) [Percent] [from <tabular object>[ OUTPUT <output clause> ][from <table or Join Condition>][< cursor name>]       

Its basic grammatical structure is as follows:

From table name  [= value]

Example:

4

SQL statement-Data manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.