create database KCGL
on
(
name='KCGL',
filename='E:\班级\姓名+学号\KCGL.mdf',
size=5,
maxsize=25,
filegrowth=20%
)
log on
(
name='KCGL_log',
filename='E:\班级\姓名+学号\KCGL_log.ldf',
size=3,
filegrowth=10%
)
--三.
USE KCGL
GO
create TABLE STUDENT
(
S_NO VARCHAR(20),
S_NAME VARCHAR(20),
S_SEX CHAR(10),
S_AGE INT,
S_ADDRESS VARCHAR(100),
S_DEPT VARCHAR(40)
)
INSERT INTO student VALUES('20111001001','王敏','女',21,'武汉','IS')
create TABLE COURSE
(
C_NO VARCHAR(20),
C_NAME VARCHAR(20),
C_CREDIT INT,
C_TYPE VARCHAR(20)
)
--若要插入所有数据按照下面的模式根据题依次插入
INSERT INTO COURSE VALUES('001','VB程序设计',4,'专业课')
create TABLE SC
(
S_NO VARCHAR(20),
SEMESTER VARCHAR(20),
C_NO VARCHAR(20),
GRADE FLOAT
)
--若要插入所有数据按照下面的模式根据题依次插入
INSERT INTO COURSE VALUES('20111001001','201101','001',78.0)
--四.
--1.
--为表STUDENT,COURSE加主键
ALTER TABLE STUDENT ADD CONSTRAINT pk_STUDENT PRIMARY KEY(S_NO)
ALTER TABLE COURSE ADD CONSTRAINT pk_STUDENT PRIMARY KEY(C_NO)
--为表SC加2外键
alter table SC add constraint fk_S_NO foreign key (S_NO) references student (S_NO)
alter table SC add constraint fk_C_NO foreign key (C_NO) references student (C_NO)
--2.
ALTER TABLE STUDENT ADD CONSTRAINT DF_STUDENT_adress DEFAULT '湖北' FOR S_ADDRESS
--3.
Alter table SC add constraint CK_SC check (SEMESTER = '201101' OR SEMESTER = '201102')
--五.
--1.
SELECT S_NAME,A_AGE,S_DEPT FROM student WHERE S_NAME = '孟凡'
--2.
select COUNT(S.S_NO) FROM SC S,student ST WHERE s_sex='女' and GRADE >80
--3.
create view KCGLVL
as
SELECT S.SNO,S.SNAME,C.Cno ,C.Grade FROM stu S,SC C WHERE S.SNO = C.SNO
--4.
create procedure KCGLPRO
@S_NO varchar(20)
as
BEGIN
select COUNT(C_NO) from SC where Sno = @S_NO
END
execute KCGLPRO '20111001001'
PS:我用的数据库是SQL SERVER 2008,剩下几题自己想想办法,做这么多及格分数已经够了。
select fph from mz_brsf
whereje >200
2.select sum(je) from mz_brsf
where sfsj >= '2012-01-01'
and sfsj <'2012-02-01'
3.delete from mz_bfsf
where cfh is null
4.update mz_bfsf
set substr(sfsj,1,4) =2013
where ks ='内科'
5. select ks, sum(je) from mz_bfsf
group by ks
having sum(je) >500
6.select top 2 ys,sum(je)
from mz_bfsf
group by ys
order by sum(je) desc
7.update a
set a.zc = b.zc
from mz_bfsf a,mz_brxx b
where a.ys = b.ys
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)