zoukankan      html  css  js  c++  java
  • SQL语句

    1.创建数据库

    create database test2;

    2.删除数据库

    drop database test2;

    3.创建表

    create table class
    (
      code varchar(20) primary key,
      name varchar(20) not null
    );

    create table ceshi

    (

      ids int auto_increment primary key,
      uid varchar(20),
      name varchar(20),
      class varchar(20),
      foreign key (class) references class(code)
    );

    **自增长 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)
    );

  • 相关阅读:
    Oracle merge
    ORA-1461 encountered when generating server alert SMG-3500
    COALESCE NVL NVL2 DECODE
    oracle限制ip訪問
    java动态代理实现与原理详细分析
    MySql/Oracle树形结构查询
    微信公众号Java接入demo
    支付宝转账
    支付宝 查看订单 退款
    linux网络编程--UNIX域套接字
  • 原文地址:https://www.cnblogs.com/u1020641/p/5966115.html
Copyright © 2011-2022 走看看