前言
由圖可以看出,表是庫的一部分,所以有庫才能使用表
show databases;? 查看已有的庫
create? database? db_name ;? 創建庫
使用? ? ?use bd_name? ? ?使用庫,之后對標進行增刪查改就只會操作這個庫里的而不影響其他庫
創建表
create? table [if not exists]? table_name(
data_name1? datatype1,? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 先是數據的名稱,再是數據的類型
data_name2? datatype2,
........? ,
data_name_n? datatype_n? ? ? ? ? ? ? ? ????????????????????????? // 請注意最后一個表結構不加逗號
);
可以看出語法有一點像 c語言 里的結構體,不過最大的不同之處在于是先變量名在變量類型之前
[] 括住的內容是可以刪去的?
查看表
查看創建表時的信息
show create table table_name /G
有一些默認值會被mysql加上,一些操作也會被mysql重新識別,
查看表的信息
desc table_name;
查看表中存儲的數據
select* from table_name;
因為還沒有存數據,所以查不到
插入兩個數據
insert into table t1 values(1,1);
insert into table t1 values(2,2);
再查詢
修改表
向表中增加一列
alter table table_name add? dataname datatype
修改表的一列
alter? table tables_name modify? dataname data_new_type;
?刪除表的一列
alter? table tables_name drop? dataname;
修改列名
alter table table_name? change oldname newname newname_type ;

修改表名?? alter table oldname rename to newname ;? ? ? ? // to 可省

刪除表
drop? table table_name;
感謝觀看