工具/材料:Management Studio。
1、首先在桌面上,点击“Management Studio”图标。
2、之后在该界面中,右键点击Student表里“设计”选项。
3、接着在该界面中,右键点击“Sno”属性里“设置主键”选项。
4、然后在该界面中,表Student设置Sno主键成功。
5、之后在该界面中,右键点击Course表里“设计”选项。
6、接着在该界面中,右键点击“Cno”属性里“设置主键”选项。
7、然后在该界面中,表Course设置Cno主键成功。
8、接着在该界面中,右键点击SC表里“设计”选项。
9、然后在该界面中,右键点击“Sno”属性里“关系”选项。
10、接着在该界面中,选择主键表为Student表里的“Sno”属性。
11、然后在该界面中,右键点击“Cno”属性里“关系”选项。
12、接着在该界面中,选择主键表为Course表里的“Cno”属性。
13、最后在该界面中,表SC设置Sno外键,Cno外键成功。
create table sc(sno char(100),
cno char(100),
grade number
)
alter table sc add constraint pk_1 primary key(sno,cno)
alter table sc add constraint sno_1 foreign key(sno) references student(sno)
alter table sc add constraint cno_1 foreign key(cno) references course(cno)
select a.*,b.*,c.grade from student a, course b ,sc c
where a.sno=c.sno and b.cno=c.cno and a.name like'张%'
select a.*,b.*,c.grade from student a, course b ,sc c
where a.sno=c.sno and b.cno=c.cno and a.xi_name in('IS','EB')
select sex,sum(age)/count(*) from student a
group by sex
select a.Stu_no,a.name,b.course_name,c.grade from student a, course b ,sc c
where a.sno=c.sno and b.cno=c.cno
select a.stu_no,c.grade from student a, course b ,sc c
where a.sno=c.sno and b.cno=c.cno and b.cno='1'
order by c.grade desc
alter table student add(inyear char(4))
update sc set grade =60 where grade between 55 and 59
delete sc where sno='200910001'
insert student into
(sno,
name,
sex
)
values
('20110001',
'张小涛',
'男'
)
CREATE TABLE [dbo].[student](
[学号] [CHAR](8) NOT NULL,
[姓名] [CHAR](8) NULL,
[性别] [CHAR](2) NULL,
[年龄] [INT] NULL,
[联系方式] [CHAR](11) NULL,
[所在院系] [CHAR](20) NULL,
CONSTRAINT [PK_student] PRIMARY KEY CLUSTERED
(
[学号] 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
ALTER TABLE [dbo].[student] WITH CHECK ADD CONSTRAINT [CK_student] CHECK (([性别]='女' OR [性别]='男'))
GO
ALTER TABLE [dbo].[student] CHECK CONSTRAINT [CK_student]
GO
ALTER TABLE [dbo].[student] WITH CHECK ADD CONSTRAINT [CK_student_1] CHECK (([联系方式] LIKE '[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'))
GO
ALTER TABLE [dbo].[student] CHECK CONSTRAINT [CK_student_1]
GO
ALTER TABLE [dbo].[student] ADD CONSTRAINT [DF_student_所在院系] DEFAULT ('电信系') FOR [所在院系]
GO
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)