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
    );

    4.删除表
    drop table ceshi;

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

    注意:
    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)
    );

    1.注释语法:--,#
    2.后缀是.sql的文件是数据库查询文件
    3.保存查询
    4.在数据库里 列有个名字叫字段 行有个名字叫记录

  • 相关阅读:
    Linux学习笔记:常用100条命令(三)
    Linux学习笔记:常用100条命令(二)
    k8s的imagePullSecrets如何生成及使用
    Jenkins基于https的k8s配置
    ubuntu supervisor管理uwsgi+nginx
    ubuntu Django + Uwsgi + Nginx 的生产环境部署
    ubuntu 安装和配置 GitLab
    ubuntu 安装harbor仓库
    ubuntu 安装Jenkins
    php过滤html标签截取部分内容
  • 原文地址:https://www.cnblogs.com/The-second/p/5966176.html
Copyright © 2011-2022 走看看