美文网首页
mysql workbench Day2

mysql workbench Day2

作者: 黄yy家的jby | 来源:发表于2018-12-13 22:23 被阅读0次

    摘要

    • 加分号
    • create database if not exists []
    • insert into student value
    • update student set age = 11
    • alter table student add/change/modify

    1. 创建数据库(scheme)

    create databases if not exists practice1;
    
    1. 不能忘记加分号
    2. if not exists 是在中间,且是exists

    2. 创建数据表(table)

    create table if not exists student(
    firstname varchar(30) not null,
    lastname varchar(30) not null,
    ID varchar(5) not null,
    Age int not null,
    primary key (ID)
    );
    

    是用() 而不是{}

    同样在数据库下 table data import wizard 可以导入一个table 运行sql后可将结果输出至csv

    3. 查看信息

    describe student;
    select * from student;
    

    4. 赋值

    INSERT INTO student VALUE ('Harry', 'Truman', '12345', 12);
    INSERT INTO student VALUE ('Shelly', 'Johnson', '12346', 13);
    INSERT INTO student VALUE ('Joe', 'White', '12347', 14);
    INSERT INTO student VALUE ('Charlie', 'Brown', '12348', 15);
    

    5.改值

    update student set Age = 11
    where ID = '12345'  ;#ID是varchar
    

    6. 增加一列删除一列

    alter table student add state varchar(5);
    alter table student add column state varchar(20) not null after gg;
    alter table student add column state varchar(20) first;
    alter table student drop state;
    

    7. 改名字改类型

    alter table student change ID student_id varchar(5);
    alter table student change `ID`  `student_id`Varchar(5) ;
    
    alter table student modify ID varchar(10);
    
    • change了之后要跟上student_id 的类型
    • 要么 `` student_IDVarchar(5)

    8. 删表

    drop table student;
    

    相关文章

      网友评论

          本文标题:mysql workbench Day2

          本文链接:https://www.haomeiwen.com/subject/orrihqtx.html