(insert) INSERT statement, (Update) modify statement, (delete) DELETE statement

Source: Internet
Author: User

1. INSERT statement Format

(1) INSERT into table name (column 1, column 2 ...) Column n) value (value 1, value 2,.... Value n); the type and order of the columns and values must be one by one corresponding, the ignored columns must allow null values to be inserted, and the columns can be in any order when inserted, but the values must correspond to the

(2) Other: Execute system stored procedure, query the attribute information of the table, EXEC sp_help Sales;

(3) Note: You can insert multi-line statements, which are separated by commas in value, such as

INSERT into dbo. Orders (OrderNo) VALUES (20), (30), (40);

(4) The function of inserting data block

To get data from another data source for inserting a table, the data source contains: 1. Other tables of the database; 2. Different databases of the same server; 3. Heterogeneous queries or other data from another one; 4. The same table

Statement: INSERT into .... SELECT (Inserts a piece of functionality one at a time)

Example:


The column information in the @MyTable is exactly the same as the column information in orders, where only a table is virtualized through a stored procedure

Use Test1
DECLARE @MyTable Table
(
Id_o int,
Order_no int,
id_p int
)
INSERT into @MyTable SELECT * from Orders;
SELECT * from @MyTable


2. UPDATE statements

Syntax: UPDATE table name SET column = value WHERE condition (optional)


3. Delete statement

Syntax: Delete table name where condition, in the process of deletion to notice whether the row is constrained by foreign keys, if the foreign key constraints then delete the main table and then delete the data, you can not delete







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.