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