SQL statement-Data manipulation

Source: Internet
Author: User

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:

INSERT  into VALUES (value 1, value 2,....)

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

INSERT  into 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(<DataValues>)[, (<data values>)] [M...N] | <TableSource> | EXEC <Prodecure> | DEFAULT VALUES}

Example:

Insert  into Values (' USA ')

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

Insert  into  values  ( ' 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:

INSERT  into < table name>[<column list>]<SELECT Statement>

Example:

Declart@MyTable Table(SalesOrderIDint, CustomerIDChar(5)              )INSERT  into @MyTable    SELECTSalesorderid,customerid fromAdventureWorks2008.Sales.SalesOrderHeaderWHERESalesOrderIDbetween 44000  and 44010;
second, UPDATE statement

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

UPDATE SET = WHERE = a value

The complete syntax structure is as follows:

UPDATE [TOP (<expression>)] [PERCENT] <Tabular Object>SET <column> = <Value> [. WRITE (<expression>,<offset>,<length>)][,<column> = <value> [. WRITE (<expression>),<offset>,<length>)]][OUTPUT <source table (s) >][WHERE <restrictive condition>]   

BASIC syntax Structure:

UPDATE < table name>SET<column>=< Value>[,<column> = <value>][from< source table (s) >][WHERE <restrictive condition>]

Example:

Update Set = ' China ' where = 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>][WHERE <search condition> | Current of [GLOBAL] <cursorName>]

Its basic grammatical structure is as follows:

DELETE  from
[WHERE= value]

Example:

Delete  from where = 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.