建立學生信息表
create table student
(
Stu_No BIGINT(80) PRIMARY KEY,
Stu_Name VARCHAR(25) NOT NULL,
Stu_Sex VARCHAR(2) NOT NULL,
College VARCHAR(40) NOT NULL,
Profession VARCHAR(40) NOT NULL,
Class INT(10) NOT NULL
);
建立課程表
create table course
(
Year VARCHAR(25),
Term INT(10),
Cou_No BIGINT(80) PRIMARY KEY,
Cou_Name VARCHAR(80) NOT NULL,
Cou_Type VARCHAR(25),
Tea_No BIGINT(80) ,
Teachar VARCHAR(25) NOT NULL,
yixuan int(3) default 0
);
建立教師表
create table teacher
(
Tea_No BIGINT(80) PRIMARY KEY,
Tea_Name VARCHAR(25) NOT NULL,
College VARCHAR(40) NOT NULL
);
建立成績表 sc
create table sc
(
Stu_No BIGINT(80),
Cou_No BIGINT(80),
Tea_No BIGINT(80),
Year VARCHAR(25),
Term INT(10),
Grade INT(10),
CONSTRAINT ab FOREIGN KEY(Stu_No) REFERENCES student(Stu_No),
CONSTRAINT ba FOREIGN KEY(Cou_No) REFERENCES course(Cou_No),
CONSTRAINT ac FOREIGN KEY(Tea_No) REFERENCES teacher(Tea_No)
);
建立選課信息表:
create table elective
(
Stu_No BIGINT(80) PRIMARY KEY,
Ele_No INT(10) NOT NULL,
Ele_Name VARCHAR(25) NOT NULL,
Ele_Type VARCHAR(25) NOT NULL,
Teachar VARCHAR(25) NOT NULL,
CONSTRAINT bc FOREIGN KEY(Stu_No) REFERENCES student(Stu_No)
);
插入數據到elective表:
insert into elective(Stu_No,Ele_No,Ele_Name,Ele_Type,Teachar)
values
(201415040401,01,'電影賞析','選修課','賀錫玉'),
(201415040402,01,'電影賞析','選修課','賀錫玉'),
(201415040403,01,'電影賞析','選修課','賀錫玉'),
(201415040404,01,'電影賞析','選修課','賀錫玉'),
(201415040405,01,'電影賞析','選修課','賀錫玉'),
(201415040406,01,'電影賞析','選修課','賀錫玉'),
(201415040407,01,'電影賞析','選修課','賀錫玉'),
(201415040408,01,'電影賞析','選修課','賀錫玉'),
(201415040409,01,'電影賞析','選修課','賀錫玉'),
(201415040410,01,'電影賞析','選修課','賀錫玉');
insert into elective(Stu_No,Ele_No,Ele_Name,Ele_Type,Teachar,xianxuan)
values
(201415040411,01,'電影賞析','選修課','賀錫玉',10);
**以上為學生管理數據庫的所有表,
要求在上述的選課信息表中建立選課觸發器(簡單些),
要求:要有觸發器,進行選課,有限選人數10人,怎麼用觸發器來實現顯示
有多少人選,或還剩幾個名額;當<=10時,可繼續選,>10結束,怎麼用觸發器用if else實現
**
ps:若所建立的選課信息表等不行,請幫忙重新建立,然後實現觸發器(麻煩簡單些)
需要再建立一張表格,存儲已選人數和未選人數。
CREATE TABLE [dbo].1 NOT NULL,
[subject_name_var] varchar NULL,
[subjet_num_int] [int] NULL,
CONSTRAINT [PK_1] PRIMARY KEY CLUSTERED
(
[int] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'科目' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'1', @level2type=N'COLUMN',@level2name=N'subject_name_var'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'人數' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'1', @level2type=N'COLUMN',@level2name=N'subjet_num_int'
GO
新增 觸發器 選擇Instead of
檢索表格 獲取行數。賦值X
IF x<'10'
begin
insert into 選課表
update 人數表
end
else
begin
不動作,或根據需要
end