SQL INSERT INTO SELECT 語句
通過 SQL,您可以從一個表複製信息到另一個表。
INSERT INTO SELECT 語句從一個表複製數據,然後把數據插入到一個已存在的表中。
INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers
WHERE Country='Germany';
建立學生表:
create table student(
Sno char(6) primary key NOT NULL,
Sname varchar(8) NOT NULL,
Ssex char(2),
Sage smallint,
sdept varchar(15)
)
use student
GO
create table course(
Cno char(4) primary key NOT NULL,
Cname varchar(20) NOT NULL,
Cpno char(4),
Ccredit tinyint
)
create table SC(
Sno char(6) NOT NULL,
Cno char(4) NOT NULL,
Grade decimal(12,2),
primary key(Sno,Cno)
)
insert into student
Values('201601','劉一','男','20','數學')
insert into student
Values('201602','劉二','男','21','語文')
insert into student
Values('201603','趙茵','男','20','SX')
insert into student
Values('201604','楊華','女','21','JSJ')