SQL Server Database inserts data

Source: Internet
Author: User

Insert a row of data
INSERT [into] table name [(column name)] VALUES (Value list)
Precautions:
(1) Each time a row of data is inserted, it is not possible to insert only half a row or a few columns of data 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
(4) If you specify that a column is not allowed to be empty when you design the table, you must insert the data
(5) inserted data items that require compliance with the requirements of the check constraint
(6) Columns with default values, you can use the default (default) keyword instead of the inserted value
Source:
INSERT into Student (studentno,loginpwd,studentname,sex,gradeid,phone,address,borndate)
VALUES (' S1200902005 ', default, ' Zhang Feng ', ' Male ', 1, ' 13212345678 ', default, ' 1987-6-2 ')


Inserting multiple rows of data
(1) The first method adds data from an existing table to a table that already exists by using the Insert SELECT statement
INSERT into < table name > (column name) SELECT < column name > from < source table name > (party: The target table must already exist before you can insert data into it)
Source:
INSERT into AddressList (name, address, email) SELECT Sname,saddress,semail from Students

(2) The second method adds data from an existing table to a new table by using the SELECT INTO statement
SELECT (column name) into < table name > from < source table name > (party: The target table does not necessarily exist, and if it does not, it will be created and then inserted into the data)
Source:
SELECT Students.sname,students.saddress,students.semail to AddressList from Students

(3) The third method is inserted by combining the data with the Union keyword
INSERT into < table name > (column name) Select < column name > union select < column name > Union ... (Party: The target table must already exist in order to insert data into it)
Source:
INSERT STUDENTS (Sname,sgrade,ssex)
SELECT ' Zhang can ', 7,1 UNION
SELECT ' Li Yang ', 4,0 UNION
SELECT ' Yang Xiao ', 2,0 UNION
SELECT ' Soup Beauty ', 3,0

SQL Server Database inserts data

Related Article

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.