zoukankan      html  css  js  c++  java
  • 表操作

    数据表 

    • 查看当前数据库中所有表
    show tables;
    
    • 查看表结构
    desc 表名;
    
    • 创建表
    • auto_increment表示自动增长
    CREATE TABLE table_name(
        column1 datatype contrai,
        column2 datatype,
        column3 datatype,
        .....
        columnN datatype,
        PRIMARY KEY(one or more columns)
    );
    

    例:创建班级表

    create table classes(
        id int unsigned auto_increment primary key not null,
        name varchar(10)
    );
    

    例:创建学生表

    create table students(
        id int unsigned primary key auto_increment not null,
        name varchar(20) default '',
        age tinyint unsigned default 0,
        height decimal(5,2),
        gender enum('男','女','人妖','保密'),
        cls_id int unsigned default 0
    )
    
    • 修改表-添加字段
    alter table 表名 add 列名 类型;
    例:
    alter table students add birthday datetime;
    
    • 修改表-修改字段:重命名版
    alter table 表名 change 原名 新名 类型及约束;
    例:
    alter table students change birthday birth datetime not null;
    
    • 修改表-修改字段:不重命名版
    alter table 表名 modify 列名 类型及约束;
    例:
    alter table students modify birth date not null;
    
    • 修改表-删除字段
    alter table 表名 drop 列名;
    例:
    alter table students drop birthday;
    
    • 删除表
    drop table 表名;
    例:
    drop table students;
    
    • 查看表的创建语句
    show create table 表名;
    例:
    show create table classes;


  • 相关阅读:
    HDUOJ---Can you solve this equation?
    HDUOJ---A + B Again
    C++知识整理(进制)
    位运算的方法,大结
    位运算的方法,小结
    C++知识整理(在此感谢大牛的整理)
    nyoj---快速查找素数
    HDUOJ----湫湫系列故事——减肥记I
    《道德经》:十条简洁有用的人生建议
    Nginx的几个常用配置和技巧
  • 原文地址:https://www.cnblogs.com/Leon27-29/p/11904069.html
Copyright © 2011-2022 走看看