T-SQL statement 4

Source: Internet
Author: User

First, insert data

1.insert Statement Introduction

Insert  into table_name (COLUMN1,COLUMN2 ... column)values(Value1,value2,......valuen)//column1,column2......column represent columns to add data records, separated by commas between columns; value1, Value2,......valuen indicates the specific value to add the record to.

Follow the principles:

1) The data type of the inserted data must be the same as the data type of the added field;

2) The size of the inserted data should be within the range of the field definition length;

3) in values, the data location that is listed must correspond to the position where the field is arranged.

2. Inserting data into some fields in the datasheet

Insert  into Values (5,98005,'  jiang Hua ',' Jilin province Liaoyuan ') Select *  from T_stud

3. Inserting data into all fields in the datasheet

Law One:

Insert  into Values (5,98005,' lily ',13658974563,' Jilin province Siping ' )Select* from T_stud

Law II:

Insert  into Values (4,98004,' jianghua ',13633569956,' Jilin province Liaoyuan ' )Select* from T_stud

3. Inserting query data into another data table

(1) INSERT INTO select mode

Insert  into table_name1 (COLUMN1,COLUMN2......COLUMNN)// Specify data table name for insert data Select// Specify the source field for the inserted data  from // Specifies the source table name of the inserted data where // represents a query condition expression

Example: Insert id,xh,xm three columns from the T_stud table into the new table.

Create TableT_stud_bak (Tiddecimal(8) not NULL, TxhChar( -), TxMChar( -))Insert  intoT_stud_bak (TID,TXH,TXM)SelectId,xh,xm fromT_studSelect* fromT_stud_bak

(2) SELECT INTO mode

Select INTO fromwhere 

Example: Inserting Xm,lldh,jtdz from a t_stud table into a new table

Select Xm,lldh,jtdz  into T_stud_back  from T_stud Select *  from T_stud_back

The difference, the way one needs to create an empty table first, the way two does not need.

T-SQL statement 4

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.