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

    表的操作

    引用: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;
  • 相关阅读:
    [JLOI2015] 管道连接
    【知识点】斯坦纳树
    [ZJOI2010] 网络扩容
    【知识点】网络流常见模型
    [NOI2009] 植物大战僵尸
    [NOI2007] 货币兑换
    【知识点】分治相关算法
    [NOI2005] 月下柠檬树
    [HNOI2012] 射箭
    [SDOI2014] 向量集
  • 原文地址:https://www.cnblogs.com/jz-no-bug/p/14229263.html
Copyright © 2011-2022 走看看