1、将现有表中的数据添加到已存在的表中:
语法:
INSERT INTO <表名>(列名)
SELECT <列名>
FROM <源表名>
2、将现有表中的数据库添加到新表中:
语法:
SELECT (列名)
INSERT INTO <表名>
FROM <源表名>
3、注意:
1、必须要有一张新表
2、新表中的列的个数,顺序,数据类型,要与被导入的表一致
3、如果有主键,不能多次插入
列1:
USE <数据库名>
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name='表名')
DROP TABLE <表名>
GO
CREATE TABLE <表名>
(
Uid int primary key(Uid) not null,
Uname varchar(50) not null,
Uaddress varchar(100),
UEmali varchar(10) check (uEmali like '%@%')
)
GO
INSERT INTO <被插表名>(列名1.列名2)
SELECT 列名1,列名2
FROM <去插入的表名>
GO
列2:
SELECT UserId,UserName,UserAddress,Phone,IDENTITY(INT,1,1) AS ID
INTO AddressList
FROM UserInfo
GO