【mysql 數據庫】05 數據庫中對錶的操作命令(不建議修改表結構)

  1. 查看當前數據庫中所有表

    show tables;



     
  2. 創建表

    格式:create table 表名(列以及類型)
    示例:create table student1(id int auto_increment primary key , name varchar(20) not null , age int not null , gender bit default 1 , address varchar(20) , isDelete bit default 0);
    說明:auto_increment 表示自增 
               primary key 主鍵
               not null  不爲空



               
  3. 刪除表

    格式:drop table 表名;
    示例: drop table car;



     
  4. 查看錶結構

    格式:desc 表名;
    示例:desc student;



     
  5. 查看建表語句

    格式:show create table 表名;
    示例:show create table student1 ;



     
  6. 重命名錶名

    格式:rename table 原表名 to 新表名
    示例:rename table student1 to newstudent;


     
  7. 修改表結構(不建議修改表結構)

    格式:alter table 表名 add | change | drop 列名 類型;

    示例:alter table newstudent add school varchar(20 ) not null;


     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章