zoukankan      html  css  js  c++  java
  • 数据库基础

    1.创建数据库
    create database test2;
    2.删除数据库
    drop database test2;

    3.创建表
    create table ceshi
    (
        ids int auto_increment primary key,
        uid varchar(20),
        name varchar(20),
        class varchar(20),
        foreign key (class)  references class(code)
    );
    create table class
    (
        code varchar(20) primary key,
        name varchar(20) not null
    );

    **自增长 auto_increment
    **主键 primary key
    **外键 foreign key (列名)  references 主表名(列名)
    **非空 not null

    4.删除表
    drop table ceshi;

    注意:
    1.类型包含长度的在类型后面加括号,括号里面写长度
    2.上一列写完加逗号
    3.最后一列不要写逗号
    4.在每一条SQL语句写完之后要加分号
    5.如果有外键关系,先创建主表



    创建表:
    create table class
    (        
        code varchar(20) primary key,    
        name varchar(20)    
    );        
    create table student
    (        
        code varchar(20) primary key,
        name varchar(20),
        sex bit,
        age int,
        class varchar(20),
        foreign key (class) references class(code)
    );        
    create table kecheng
    (         
        code varchar(20) primary key,
        name varchar(20)
    );
    create table teacher
    (
        code varchar(20) primary key,
        name varchar(20)
    );
    create table chengji
    (    
        ids int auto_increment primary key,
        scode varchar(20),
        kcode varchar(20),
        degree float,
        foreign key (scode) references student(code),
        foreign key (kcode) references kecheng(code)
    );
    create table tkecheng
    (
        ids int auto_increment primary key,
        tcode varchar(20),
        kcode varchar(20),
        foreign key (kcode) references kecheng(code),
        foreign key (tcode) references teacher(code)
    );

  • 相关阅读:
    拉格朗日插值模板题 luoguP4871
    FFT P3803 [模板]多项式乘法
    codeforces #629 F
    codeforces #629 E-Tree Queries
    数学—线性基
    codeforces #629 D.Carousel
    luogu P1447_能量采集 (莫比乌斯反演)
    luogu P2257- YY的GCD (莫比乌斯反演)
    luogu P2522-Problem b (莫比乌斯反演)
    luogu P3455 (莫比乌斯反演)
  • 原文地址:https://www.cnblogs.com/sunzhenkun/p/7357382.html
Copyright © 2011-2022 走看看