創建資料庫

create database 資料庫名;
創建資料庫的時候,我們應該記住以下幾點:
1 不能與其他資料庫名重複
2 名稱可以由任意字母,阿拉伯數字,下劃線,美元符,但是必須以字母開頭
3 名稱最長為64個字元,別名最長可為256個字元
4 在windows系統下,資料庫名稱不區分大小寫,在linux下區分大小寫

查看資料庫

show databases;
查看所有的資料庫

選擇資料庫

use 資料庫名;

刪除資料庫

drop database 資料庫名稱;
這一步操作千萬要謹慎,不然已經刪除的資料庫可能會找不回來了,這種操作太危險了,而且不是很常用

創建數據表

create table 表名;
還有其他許多屬性
create table 表名 (列名1 屬性, 列名2 屬性...);

查看錶結構

有三種方式
1 show columns from 表名 from 資料庫名稱;
2 show columns from 資料庫名稱.表名
3 desc 表名
4 查詢某個欄位 desc 表名 欄位

修改表結構

alter table 數據表名 。。。。
比如我們添加一個欄位emil 類型為varchar(50) not null, 將欄位user的類型由varchar(30)變為varchar(40)
alter table tb_admin add emil varchar(50) not null, modify user varchar(40);

重命名表名

rename table 數據表名1 to 數據表名2

刪除表

drop table 表名;

插入數據

insert into 表名(欄位名) values(欄位值);

查詢數據

select [distinct][concat(col1,":",col2)] as collection_list
from 表名 指定數據表
where primary_constrait 查詢條件
group by grouping_colums 如何對結果進行分組
order by sorting_columns 如何對結果進行排序
having secondary_constrait 查詢條件
limit count 限制輸出

修改記錄

update 表名 set 欄位名=新的值 where 條件;

刪除記錄

delete from 表名 where 條件;

推薦閱讀:

相关文章