zoukankan      html  css  js  c++  java
  • SQL语句总结表操作

    https://blog.csdn.net/hallomrzhang/article/details/85010014

    表的操作

    1.查看表结构

    desc 表名

    2.创建表结构的语法

    create table table_name(
    字段名 数据类型 可选的约束条件);

    demo:创建班级和学生表

    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
    )
    

    3.修改表–添加字段

    alter table 表名 add 列名 类型
    demo:alter table students add birthday datetime;

    4.修改表–修改字段–重命名版

    alert table 表名 change 原名 新名 类型及约束
    demo:alter table syudents change birthday birth  datetime not null;
    

    5.修改表–修改字段–不重命名

    alter table 表名 modify 列名 类型及约束
    demo : alter table students modify birth date nout noll;
    

    6.删除表–删除字段

    alter table 表名 drop 列名
    demo :later table students drop birthday;
    

    7.删除表

    drop table 表名
    demo:drop table students;
    

    8.查看表的创建语句–详细过程

    show create table 表名
    demo : show create tabele students;
  • 相关阅读:
    qbzt day6 上午
    qbzt day5 下午
    qbzt day5 上午
    【7.24校内交流赛】T3【qbxt】复读警告
    【7.24校内交流赛】T1&T2
    一个一定要好好提溜出来的贪心题
    7.19 讲题
    DP大大大大大赏
    图论经典例题大赏
    数据结构题大赏
  • 原文地址:https://www.cnblogs.com/linmob/p/14162878.html
Copyright © 2011-2022 走看看