SQL insert into statement

Source: Internet
Author: User

SQL insert into statement

Add data to a table using the INSERT statement. The insert into statement can be used to append a record table or append multiple records from one table to another.

The syntax of the INSERT statement is:

Insert into table_name (column1, column2 ,...)
VALUES (value1, value2 ,....)

Instance

Insert into AntiqueOwners (OwnerID, OwnerLastName, OwnerFirstName)
VALUES (4, 'Peter ', 'novitski ')

To add a specific record table, the insert into statement is followed by the table name and domain name. Insert each clause value in the value to the position of the corresponding field value in the list: the first value is inserted in the first field, enter the second of the second field, etc.

This will cause a record to be inserted into the AntiqueOwners table. This new record will have 4 OwnerID, a Peter OwnerLastName and Novitski OwnerFirstName.

Note: If you omit the field list, you must include the values of each field in a table. Otherwise, the Operation will fail. Values must also be separated by commas. Text and date fields must also be enclosed in single quotes ('').

An automatic number field (also known as the Anti-terrorism field) is a data type that automatically creates and stores a number for each project to be added to the table. If you do not want the AutoNumbered field to be re-numbered, you must include the auto-numbered field in the query. If the automatic number field is not included, the additional project will be assigned a new value for the automatic number field.

Example #2

Insert into AntiqueOwners (OwnerID, OwnerLastName, OwnerFirstName)
SELECT EmployeeIDNo, LastName, FirstName
FROM EmployeeAddressTab
Le
WHERE City = 'upton'

When a Select statement is used before the insert into statement of the Multi-record syntax, one or more records are added to the table. This is called append query and replication because it records from one or more tables to another. The records in this table are appended and are not affected by the operation.

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.