1. 程式人生 > 資料庫 >mysql基礎-增刪改查簡單使用快速概覽

mysql基礎-增刪改查簡單使用快速概覽

簡單使用快速概覽

  • show databases; 檢視所有的庫
    use 庫名;  進入這個庫
    show tables;  在當前使用的庫中,檢視所有表
    show tables from 庫名; 在任意地方,均可以檢視其它庫中的所有表
    select database();  在某個庫中,使用database()函式來查詢當前所在庫的庫名
    desc 表名;  檢視這個表的內容資訊
  • 新建表,參考示例:
    create table stuinfo(
      stuid int,
      stuname varchar(20),
      gender char,
      borndata datetime
    );
  • 在表中插入資料
    alter table stuinfo convert to character set utf8;  【將表中的所有字符集更改為utf8】
    insert into stuinfo values(1,'張無忌','男','1998-3-3'); 【插入一條資料】
    ​
    修改表中資料
    update stuinfo set borndate='1980-1-1'; 【將這個表中的所有borndate改為1980-1-1】
    update stuinfo set borndate='1995-1-1' where stuid=2; 【將這個表中的stuid=2那一行的borndate改為1980-1-1】
    ​
    刪除表中一條資料
    delete from stuinfo where stuid=1;  【刪除stuid=1的這條資料】
    ​
    ​
    修改表結構,新增一個列名
    alter table stuinfo add column email varchar(20); 【新增一列,列名為email】
    ​
    刪除一張表
    drop table stuinfo; 【刪除指定表】
  • 註釋;
    單行註釋-1
    #abcx
    -- abcx
    ​
    多行註釋
    /*
    sdfadfaf
    */