T-SQL (5)-Operation Data Line (RUI)

Source: Internet
Author: User

Inserting data rowsINSERT  [ into] <Table name>  [Column Name] VALUES <Value List>INSERT  intoStudents (sname,saddress,sgrade,semail,ssex)VALUES('Zhang Qing cutting','Shanghai Songjiang',6,'[email protected]',0) Precautions:1: It is not possible to insert only half a row or columns of data each time a row is inserted, so whether the inserted data is valid will be checked according to the integrity of the entire line;2: The data type, precision, and scale of each data value must match the corresponding column;3: Cannot specify a value for an identity column because its number is automatically increased;4: If you specify that a column is not allowed to be empty when you design the table, you must insert the data;5: An inserted data item that requires compliance with the requirements of the check constraint6: Columns with default values, you can insert multiple rows of data using the default (default) keyword instead of the inserted value 1INSERT  into <Table name>(column name)SELECT <Column Name> from <source table Name>INSERT  intoTongxunlu ('name','Address','Email')SELECTSname,saddress,semail fromStudents inserting multiple rows of data2SELECT(column name) into <Table name> from <source table Name>SELECTStudents.sname,students.saddress,students.semail intoTongxunlu fromstudents The question is, how do I insert a new identity column when select INTO inserts multiple rows of data? SELECT IDENTITY(data type, identity seed, identity growth) asColumn Name intoNew Table fromOriginal TableSELECTStudents.sname,students.saddress,students.semail,IDENTITY(int,1,1) asStudentID intoTongxunluex fromStudents inserting multiple rows of data3INSERT  into <Table name>(column name)SELECT <Column Name> UNIONSELECT <Column Name> UNION...INSERTSTUDENTS (sname,sgrade,ssex)SELECT 'Test Girl 1',7,0 UNIONSELECT 'Test Girl 2',7,0 UNIONSELECT 'Test Girl 3',7,0 UNIONSELECT 'Test Girl 4',7,0 UNIONSELECT 'Test Girl 1',7,0 UNIONSELECT 'Test Boys 2',7,1 UNIONSELECT 'Test Boys 3',7,1 UNIONSELECT 'Test Boys 4',7,1 UNIONSELECT 'Test Boys 5',7,1Update Data rowsUPDATE <Table name> SET <Column Name=Update values>[WHERE < update conditions >]UPDATEScoresSETScores=Scores+ 5WHEREScores<=  theDelete data rowsDELETE  from <Table name> [WHERE < Delete condition >]or:TRUNCATE TABLE <Table name>here Delete fromStudents=TRUNCATE TABLEStudents querying data rows because data queries are the most common way to manipulate data rows, we discuss them separately below. 

T-SQL (5)-Operation Data Line (RUI)

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.