1. 程式人生 > >MySQL語法練習

MySQL語法練習

create database study;                        --新建一個名為study的資料庫
use study;
create table home(                            --在study資料庫下建立一個名為home的資料表,含有unit和num
unit int,
num int
);
create database building;                     --新建一個名為building的資料庫
use building;
create table room like study.home;            --將home資料表複製到building資料庫中,命名為room
alter table room add floor int after unit;    --在資料表room中,欄位unit之後加入新的欄位floor
alter table room modify unit varchar(10);     --修改building資料庫room表中unit的欄位型別為varchar
alter table room change num number int;       --修改building資料庫room表中unit的欄位型別為varchar
alter table room drop unit;                   --刪除study資料庫下home資料表的unit 欄位
show create database study;                   --檢視study的建立語句
alter database study charset gbk;             --修改study的庫選項
show create table room;                       --檢視building資料庫下表room的建立語句
alter table room engine innodb;               --修改building資料庫下表room的建立語句,儲存引擎改為innodb
drop table room;                              --刪除building資料庫下的room資料表
use study;
drop table home;                              --刪除study資料庫下的home資料表
drop database study;                          --刪除study、building資料庫
drop database building;