zoukankan      html  css  js  c++  java
  • SQL创建表格——手写代码

    打开phpstudy,打开Navicat for MySQL,进入要创建表格的数据库,点击上方“查询”按钮,“创建查询”,即可输入代码进行创建。

    例:

    create table class
    (
     class_id int not null  primary key,
     class varchar(255) not null,
     major varchar(255) not null ,
     depart varchar(255) not null
    );
    create table stu_info
    (
     id int not null primary key,
     name varchar(90) not null ,
     sex varchar(100) not null,
     age int,
     class varchar(20) not null,
     foreign key (class) references class(class_id)
    );
    create table score
    (
     ids int auto_increment  primary key,
     stu_id int not null,
     subject varchar(255) not null,
     score int not null
    );

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

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

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

  • 相关阅读:
    记录排序算法
    Redis 记录
    ELK Windows环境 强行记录
    前端组件 bootstrap-select 下拉 多选 搜索
    记一次微信点赞小网站的事故
    来自加班的吐槽
    .net 比较器
    做一个.net core 小项目 遇到的一些坑
    即使通讯架构
    resultMap 映射
  • 原文地址:https://www.cnblogs.com/cmzhphp2017/p/7547340.html
Copyright © 2011-2022 走看看