1. 程式人生 > 其它 >資料庫系統概論(第五版),作者王珊,薩師煊,課本例子的程式碼,表和資料與課本一致,親測可直接食用

資料庫系統概論(第五版),作者王珊,薩師煊,課本例子的程式碼,表和資料與課本一致,親測可直接食用

技術標籤:資料庫sql建立資料庫建立表插入資料

資料庫SQL的具體講解,請點選資料庫的詳細知識,請點選這裡
第一步:建立資料庫

create database stu
on primary
(	
	name="stu_data", /*主資料檔案的邏輯名*/
    filename="D:\testdb\stu_data.mdf", /*主資料檔案儲存位置*/
    size=3mb,  /*主資料檔案的初始大小*/
    maxsize=100mb,  /*主資料檔案的最大大小,不寫就是沒有限制*/
    filegrowth=1mb /*增量為1MB*/
)
log on ( name="stu_log", /*主資料檔案的邏輯名*/ filename="D:\testdb\stu_log.ldf", /*主資料檔案儲存位置*/ size=3mb, /*主資料檔案的初始大小*/ maxsize=100mb, /*主資料檔案的最大大小,不寫就是沒有限制*/ filegrowth=1mb /*增量為1MB*/ )

第二步,建立表


create table s
(
	sno int primary key,
	sname nvarchar(50) unique,
	ssex nvarchar(
50), sage int, sdept nvarchar(50), ); create table c ( cno int primary key, cname nvarchar(50), cpno int , ccredit nvarchar(50), foreign key (cpno) references c (cno), ) create table sc ( sno int foreign key references s(sno), cno int foreign key references c(cno), grade nvarchar(50), primary
key(sno,cno), )

第三步,插入資料


insert into s values
(21,'李勇','男',20,'cs'),
(22,'劉晨','女',19,'cs'),
(23,'王敏','女',18,'ms'),
(24,'張立','男',19,'is')


insert into c values
(1,'資料庫',5,4),
(2,'數學',null,2),
(3,'資訊系統',1,4),
(4,'作業系統',6,3),
(5,'資料結構',7,4),
(6,'資料處理',null,2),
(7,'pascal語言',6,4)

insert into sc values
(21,1,92),
(21,2,85),
(21,3,88),
(22,2,90),
(22,3,80)

親測有用,求點贊