zoukankan      html  css  js  c++  java
  • 2015/4/2 sql数据库创建表 表的关联

    1.建立一个“学生”表 Student

    create table student_muanfeng(

    sno char(4) primary key(主键),

    Sname char(20) unique(为约束),

    Ssex char(2) null check(sex in('M','F')),

    Sage smallint null check(age>18 and age<25),

    Sdept char(20)

    );

    2.建立一个“课程”表Course

    Create table Course(

    Cno char(4) primary key,

    Cname char(40),

    Credit smallint null check(credit>0 and credit<10)

    );

    )

    3,建立学生学生选课表 SC

    Create table SC 

    sno char(4) not null ,cno char(4) not null primary key(sno,cno),
    grade smallint null check(grade>0 and grade <100))
    alter table SC add constraint fk_sno foreign key(sno) references Student(sno);
    alter table SC add constraint fk_cno foreign key(cno) references Course(cno);

    2.Create table SC(

    Sno char(4),

    Cno Char(4),

    Primary key (Sno,Cno),

    Frimary key(Sno) reference student(Sno),

    Frimary key(Cno) reference Course(Cno),

    );

     插入数据:

    insert into 表名称(条件)value(相对应的值)

  • 相关阅读:
    shell命令--stat
    英文段子
    OCP读书笔记(16)
    shell命令--uptime
    OCP读书笔记(15)
    shell命令--dmesg
    OCP读书笔记(14)
    shell命令--hostname
    OCP读书笔记(13)
    shell命令--uname
  • 原文地址:https://www.cnblogs.com/muanfeng/p/4389094.html
Copyright © 2011-2022 走看看