zoukankan      html  css  js  c++  java
  • Sql Server 2005数据库sql代码写外键、复合键作主键

    01.use ClassDB  
    02.drop table enrol /*引用student 和classes*/  
    03.drop table student/*被enrol引用*/  
    04.drop table admin/*未被引用*/  
    05.drop table classes/*引用course和teacher同时被classes引用*/  
    06.drop table course/*被classes引用*/  
    07.drop table teacher/*被classes引用*/  
    08./*创建课程表*/  
    09.create table course(  
    10.id int primary key identity,  
    11.name varchar(20) not null,  
    12.mark int not null,  
    13.prepare varchar(10) not null,  
    14.dep varchar(10) not null  
    15.)  
    16./*创建教师表*/  
    17.create table teacher(  
    18.id int primary key identity,  
    19.name varchar(20) not null,  
    20.title varchar(50) not null,  
    21.password varchar(50) not null,  
    22.)  
    23./*创建学生信息表*/  
    24.create table student(   
    25.id int primary key identity,  
    26.name varchar(10) not null,  
    27.password varchar(50) not null,  
    28.jiguan varchar(10) not null,  
    29.department varchar(10) not null,  
    30.sex varchar(10) not null,  
    31.mark int not null,  
    32.tel varchar(50),  
    33.e_mail varchar(50)  
    34.)  
    35./*创建管理员信息表*/  
    36.create table admin(  
    37.id int primary key identity,  
    38.ad_name varchar(10) not null,  
    39.password varchar(10) not null  
    40.)  
    41./*创建班级信息表,其中教师id和课程id作为班级信息表的外键*/  
    42.create table classes(  
    43.id int primary key identity,  
    44.tea_id int not null,  
    45.cour_id int not null,  
    46.foreign key(tea_id) references teacher(id),  
    47.foreign key(cour_id) references course(id),  
    48.room_id varchar(50) not null,  
    49.cour_time char(10) not null  
    50.)  
    51./*选课信息表,其中下面为复合主键*/  
    52.create table enrol(  
    53.stu_id int not null,  
    54.class_id int not null,  
    55.foreign key(stu_id) references student(id),  
    56.foreign key(class_id) references classes(id),  
    57.accept bit not null,  
    58.score varchar(50) not null,  
    59.primary key(stu_id,class_id)/*创建复合主键*/  
    60.)  
    
  • 相关阅读:
    作业五:团队项目——项目启动及需求分析
    结对编程项目---四则运算
    PSP记录个人项目耗时情况
    代码复查
    是否需要有代码规范?
    编写一个能自动生成小学四则运算题目的程序。
    目前流行的源程序版本管理软件和项目管理软件的优缺点
    在Github注册账户
    浏览完整部教材,列出不懂的5-10个问题
    FZU 1683 纪念SlingShot(矩阵水)
  • 原文地址:https://www.cnblogs.com/xinzehome/p/2878311.html
Copyright © 2011-2022 走看看