• Mysql ==》 文件(表)


    表介绍:

    表相当于文件,表中的一条记录就相当于文件的一行内容,不同的时,表中的一条记录有对应的标题,称为表的字段。

    例如: id,name ,age 就称为字段,其余的,一行内容称为一条记录。

    1.创建表

    语法:
    create table 表名(
    字段名1 类型[(宽度) 约束条件],
    字段名2 类型[(宽度) 约束条件]
    );
    
    例子:
    create table t1 (id int,name char(12));
    create table t1 (id int,name char(12)) engine =innodb default charset utf8;
    注意: 1.在用一张表中,字段名是不能相同的。 2.宽度和约束条件可选,即 可有可无 3.字段名和类型时必须的。

    2.查看表

    语法:
    1.show tables;
    2.show create table t1;
    
    查看表结构:
    1.describe  t1;  
    2.desc  t1;
    

    3.修改表

    语法:
    1. alter table t1 modify name char(12);   #修改表中字段的宽度
    2. alter table course charset = utf8;        #修改表中的类型
    3.alter table t1 modify name char(12) character set utf8; #修改表中的类型
    4.alter table t1 rename t2;         #重命名表的名字
    5.alter table t1 add age int;   #添加表中的字段
    6.alter table t1 drop age;      #删除表中的字段
    7.alter table t1 modify id int  not null primary key auto_increment;  #修改为主键和自动增长
    8.alter table t1 modify id int  not null;   #删除自增约束
    9.alter table t1 drop primary key;   #删除主键
    

    4.复制表

    复制表结构+记录(key 不会被复制: 主键、外键和索引)
    语法:
    1. create table new_t1 select * from t1;
    
    只复制表结构:
    1.select * from t1 where 1=2;  #条件为假,查不到任何记录,所以不会复制表的记录
    2.create table new_t2 select * from t1 where 1=2;  #只复制表的结构
    

    5.删除表

    语法:
    drop  table  表名;
    
    例如:
    drop  table t1;
    

      

  • 相关阅读:
    poj 2186 && hdu 3836
    poj 2833 The Average
    hud 3062 Party
    论 ACM 与泡妞 (转载)
    poj 1064 Cable master
    poj Candies
    [转]人才流失的背后
    获取存储过程的ReturnValue值
    javascript js jquery获取元素位置代码总结
    【引用】xmlpath 操作 xml
  • 原文地址:https://www.cnblogs.com/zhongbokun/p/7496197.html
Copyright © 2020-2023  润新知