Inserting data into a table using the Insert SELECT
-- Add the data inserted in T1 to T2 (the T2 table must exist, and the order, data type must be consistent with T1) INSERT into T2 (Username,password) SELECT from T1
Use SELECT into to add data from an existing table to a new table
-- Add the data that is queried in T1 to T2 (the T2 table cannot exist.) will be created in execution)SELECT t1_username, T1_password into from T1
To insert an identity column:
-- when inserting, the data for the identity column is not allowed to be specified. -- if you want to insert an identity column, you can create a new identity column: Identity (type, seed, increment) as column SELECTidentity(int 1 1 as t1_id, T1_username, T1_password into from T1
Inserting data using UNION merge
--UNION combines different data or query results into a new result set--the effect is the same as the INSERT SELECT, except that the data is handwritten ...INSERTT1 (Username,password)SELECT 'a','123456' UNION SELECT 'b','123456' UNION SELECT 'C','123456' UNION SELECT 'D','123456' UNION SELECT 'e','123456' UNION SELECT 'F','123456'
T-SQL inserts multiple rows of data at once