Insert a data row using insert
[Insert row of data at once]
Full write:
INSERT into Renshi (name, sex, age, tel)
VALUES (' Hu elder sister ', ' female ', ' 35 ', ' 136334***12 ')
Shorthand:
INSERT Renshi
VALUES (' Hu elder sister ', ' female ', ' 35 ', ' 136334***12 ')
Insert data for the default value column
INSERT into Renshi
VALUES (' Hu elder sister ', ' female ', ' + ',DEFAULT)
displaying results: Hu elder sister female (NULL)
Error wording:
INSERT Renshi VALUES (' Hu elder sister ', ' female ', ' 35 ')
Insert error: The column name or the number of supplied values does not match the table definition.
INSERT into Renshi (id,name, sex, Age, tel) VALUES (' 1 ', ' Hu elder sister ', ' female ', ' 35 ', ' 136334***12 ')
The INSERT statement cannot specify a value for an identity column because its number is automatically increased.
[insert multiple rows of data at once]
to add data from an existing table to a new table by using the Insert SELECT statement
INSERT into Renshi_ (Name,sex,age,tel)
SELECT Name,sex,age,tel
from Renshi
The number of data that is inserted in the order data type must be consistent with the inserted item.
Second add data from an existing table to a new table by using the SELECT INTO statement ( cannot be pre-existing )
SELECT Name, Sex,age,tel
into renshi__
from Renshi
The difference from the above insertion: this new table is created when executing a query statement and cannot be pre-existing.
The identity column is not allowed to be specified, so we can create a new identity column.
SELECT IDENTITY (int,1,1) as ID, name, Sex,age,tel
into renshi__
from Renshi
Triple insert by combining data with the Union keyword
The Union statement is used to combine two different data or query results into a new result set
INSERT into Renshi (name, Sex,age,tel)
SELECT ' Hu elder sister _1 ', ' female ', ' a ', ' UNION
SELECT ' Hu elder sister _2 ', ' female ', ' a ', ' UNION
SELECT ' hu elder sister _3 ', ' female ', ' a ', ' UNION
SELECT ' Hu elder sister _4 ', ' female ', ' a ', ' UNION
SELECT ' Hu elder sister _5 ', ' female ', ' 35 ', '
SQL INSERT statement Note