4.20 mysq数据库 创建表

  创建表

        创建表的时候必须进入数据库       

            create table www(
            id int,
            name varchar(20)
            );

  查看表 

         show tables xxx;

  删除表 

          drop table www;

  查看表结构

          desc www; 

  虚拟表

          虚拟表概念:将查询出来的结果(一张表)当做表来操作

          将虚拟表保存起来(放到变量里面去)就是视图 

  主键

      给一个表加主键,就可以做到“唯一区分”。   userid varchar(20) not null primary key comment       '这是账号',   (primary key 主键,表的一列不能重复,用于唯一,比如账号、用户名)        

  练习

drop table if exists login;  '如果存在这个表,就会删掉'
create table login(
    userid varchar(20) not null primary key comment     '这是账号',
    password varchar(20) not null comment         '这是密码',
    username varchar(10)comment         '这是用户名',
    sex int(1) default 1 comment             '1代表男,0代表女'    
);
创建一个登录表

 

drop table if exists zy1;
create table zy1(
    id int auto_increment not null,
    f1 float comment '注释1',
    f2 decimal(20,5) default 12.3,
    f4 varchar(20) comment '这是一个注释',
    id2 int,
    primary key(id),
    unique key(f1),
    key(f2),
    foreign key(id2) references set_test(id)
)    
    comment = '这是一个建表大全语句',
    engine = MyIsam,
    auto_increment = 1000;
表练习

 

原文地址:https://www.cnblogs.com/cp123/p/8897986.html