SQL

--@@@@@@@@@@@用DDL进行对表的定义@@@@@@@@@@@ 
--判断是否已经有这个数据库了 
use master 
if exists(select * from sysdatabases where name = 'SECMS') 
drop database SECMS 
go 
exec xp_cmdshell 'mkdir E:\SECMS\DB' 
--创建数据库 
create database SECMS on 
( 
--主数据库文件的具体描述 
name='SECMSDB', 
filename='E:\SECMS\DB\SECMS_Data.mdf', 
size=3, 
maxsize=5, 
filegrowth=15% 
) 
log on 
( 
--日志文件的具体描述 
name='SECMSDBLog', 
filename='E:\SECMS\DB\SECMS_log.ldf', 
size=512kb, 
maxsize=5, 
filegrowth=15% 
) 
go 

use SECMS 
go 

if exists(select * from sysobjects where name='tbl_student') 
drop table tbl_student 
create table tbl_student 
( 
stuNo char(8) primary key,--学号,主键 
stuName char(8) not null,--姓名 
stuSex char(2) not null,--性别 
stuEnterYear int not null,--入学年份 
stuClass int not null,--班级 
stuID varchar(18) not null,--学的的身份证号码 
stuPassword varchar(8)  default '12345678',--用于登录系统的初始密码 
stuAddress varchar(50) null,--学的籍贯 
stuPicPath varchar(80) null--存放学生照片的文件夹路径 
) 

if exists(select * from sysobjects where name='tbl_teacher') 
drop table tbl_teacher 
create table tbl_teacher 
( 
tchNo char(8) primary key,--教师编号,主键 
tchName char(8) not null,--教师姓名 
tchPassword char(8) not null default '86754321'--教师登录系统的初始密码 
) 

if exists(select * from sysobjects where name='tbl_exam') 
drop table tbl_exam 
create table tbl_exam 
( 
examNo char(8) PRIMARY KEY ,--考试编号,主键 
examName varchar(20) null,--考试名称 
examType char(4) null,--考试类型 
examBeginApplyTime varchar(10) null,--考试报名时间,格式:2009-02-01 
examDeadline varchar(10) null,--考试报名结束时间 
examTime varchar(20) null,--考试时间,格式2009-02-01 14:30 
testDuration varchar(10) null,--整个考试用时 
examApplyCondition varchar(20) null,--考试报名条件 
examAddress varchar(50) null,--考试地点 
examDatum varchar(7000) null--考试资料列表 
) 

if exists(select * from sysobjects where name='tbl_se') 
drop table tbl_se 

create table tbl_se 
( 
stuNo char(8) FOREIGN KEY REFERENCES tbl_student(stuNo),--外键 
examNo char(8) FOREIGN KEY REFERENCES tbl_exam(examNo),--外键 
examScore float(8) null,--考试成绩 
isExamPass int null --考试是否通过.1表示通过,0表示未通过 
) 

if exists(select * from sysobjects where name='tbl_set') 
drop table tbl_set 

create table tbl_set 
( 
stuNo char(8) FOREIGN KEY REFERENCES tbl_student(stuNo),--外键 
examNo char(8) FOREIGN KEY REFERENCES tbl_exam(examNo),--外键 
tchNo char(8) FOREIGN KEY REFERENCES tbl_teacher(tchNo),--外键 
isQualification char(2) default '是',--是否通过."是"或"否" 
failureReason varchar(200) null--未通过审查的原因 
) 



你可能感兴趣的:(sql,XP,Go)