有人能帮我看看这段代码有没有问题啊?帮忙修改一下
CREATE DATABASE lection
on
(name=lection1_dat,
FILENAME = 'd:\lection_data.mdf',
size=10,
maxsize=50,
filegrowth = 10
)
log on
(name='lection_dat',
filename='d:\lectionlog.ldf',
size=5,
maxsize=25,
filegrowth=5
)
use lection
create table 学生
(学号 int primary key,
姓名 char(15),
学院 char(15),
专业 char(30),
已修学分 int,
课名1 varchar(50),
课名2 varchar(50),
课名3 varchar(50)
)
insert into 学生 values('2002321001','张三','文法学院','文秘','10')
insert into 学生 values('2003321002','李四','外语学院','日语','8')
insert into 学生 values('2004321003','王五','信息学院','信息管理','3')
Go
create table 选课表
(学号 int not null,
学院 char(30) not null,
课名 varchar(50) not null,
课号 int not null,
学分 int not null,
选取标志 int not null
)
insert into 选课表 values('2002321001','文法学院','传播学','101','1','1')
insert into 选课表 values('2003321002','外语学院','音乐欣赏','102','1','1')
insert into 选课表 values('2004321003','信息学院','汽车文化','103','1','1')
create Table 学院办公室
(学院 char(30) primary key,
电话 int,
地址 char(30)
)
Go
insert into 学院办公室 values('文法学院','2385123','1号楼')
insert into 学院办公室 values('外语学院','2385321','2号楼')
insert into 学院办公室 values('信息学院','2385864','3号楼')
alter table 选课表
add constraint pk1
foreign key(学号)
references 学生(学号)
go
alter table 选课表
add constraint xq
check(选取标志=o or 选取标志=1)
go
create trigger tr1
on
for insert
as
declare @yxxf int
select @yxxf=已修学分 from 学生
where 学号=@xh
if @yxxf>=16
begin
raiserror('学分已修满',16,1)
rollaback
end
declare @bz int,@xf int,@xh int,@km varchar(50),@km1 varchar(50),@km2 varchar(50),@km3 varchar(50)
select @bz=选取标志
@xf=学分
@xh=学号
@km=课名
@km1=课名1
@km2=课名2
@km3=课名3
from inserted
if @bz=1 and @km1 is null
begin
update 学生
set 已修学分=已修学分+@xf
set @km1=课名
where 学号=@xh
end
if @bz=1 and @km1 is not null and @km2 is null
begin
update 学生
set 已修学分=已修学分+@xf
set @km2=课名
where 学号=@xh
end
if @bz=1 and @km1 is not null and @km2 is not null and @km3 is null
begin
update 学生
set 已修学分=已修学分+@xf
set @km3=课名
where 学号=@xh
end
if @bz=1 and @km1 is not null and @km2 is not null and @km3 is not null
begin
raiserror('学分已修满',16,1)
rollaback
end
create view v
as
select 学生.学号,姓名,学生.学院,专业,已修学分
from 学生 inner join 选课表
on 学生. 学号=选课表. 学号
inner join 学院办公室
on 学院办公室.学院=选课表.(学号,学院,选取标志,学分)
create proc input_proc
@xh int,@xy char(30),@xf int
as
insert 选课表学院
values
( @xh,@xy,@xf)
go
insert into 学生 values
('2002321001','张三','文法学院','文秘','10')
insert into 学院办公室 values
('文法学院','2385123','1号楼')
insert into 选课表 values
('2002321001','文法学院','传播学','101','1','1')
select *
from 学生
问题点数:20、回复次数:3Top
1 楼comerliang(天地良心)(性欲被自己倒分倒没了,以后再也不敢倒分了,想倒分的兄弟看看我的下场吧,男人没了性欲真不爽)回复于 2005-05-14 10:38:25 得分 5
use lection
前加
go
Top
2 楼comerliang(天地良心)(性欲被自己倒分倒没了,以后再也不敢倒分了,想倒分的兄弟看看我的下场吧,男人没了性欲真不爽)回复于 2005-05-14 10:50:33 得分 15
CREATE DATABASE lection
on
(name=lection1_dat,
FILENAME = 'd:\lection_data.mdf',
size=10,
maxsize=50,
filegrowth = 10
)
log on
(name='lection_dat',
filename='d:\lectionlog.ldf',
size=5,
maxsize=25,
filegrowth=5
)
go
use lection
go
create table 学生
(学号 int primary key,
姓名 char(15),
学院 char(15),
专业 char(30),
已修学分 int,
课名1 varchar(50),
课名2 varchar(50),
课名3 varchar(50)
)
insert into 学生(学号, 姓名, 学院, 专业, 已修学分) values('2002321001','张三','文法学院','文秘','10')
insert into 学生(学号, 姓名, 学院, 专业, 已修学分) values('2003321002','李四','外语学院','日语','8')
insert into 学生(学号, 姓名, 学院, 专业, 已修学分) values('2004321003','王五','信息学院','信息管理','3')
Go
create table 选课表
(学号 int not null,
学院 char(30) not null,
课名 varchar(50) not null,
课号 int not null,
学分 int not null,
选取标志 int not null
)
insert into 选课表 values('2002321001','文法学院','传播学','101','1','1')
insert into 选课表 values('2003321002','外语学院','音乐欣赏','102','1','1')
insert into 选课表 values('2004321003','信息学院','汽车文化','103','1','1')
create Table 学院办公室
(学院 char(30) primary key,
电话 int,
地址 char(30)
)
Go
insert into 学院办公室 values('文法学院','2385123','1号楼')
insert into 学院办公室 values('外语学院','2385321','2号楼')
insert into 学院办公室 values('信息学院','2385864','3号楼')
alter table 选课表
add constraint pk1
foreign key(学号)
references 学生(学号)
go
alter table 选课表
add constraint xq
check(选取标志=0 or 选取标志=1)
go
后面的部分没大看懂,自己搞定吧Top
3 楼UnoGod(夏天行)回复于 2005-05-14 11:30:40 得分 0
谢谢^Top




