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.)  
    
  • 相关阅读:
    洛谷 P1628 合并序列
    洛谷 P3378 【模板】堆
    浅谈可删除堆
    浅谈数据结构—分块
    浅谈对顶堆
    JDOJ 1929: 求最长不下降序列长度
    JDOJ 1928: 排队买票
    Leetcode(53)-最大子序和
    Leetcode(38)-报数
    Leetcode(35)-搜索插入位置
  • 原文地址:https://www.cnblogs.com/xinzehome/p/2878311.html
Copyright © 2011-2022 走看看