數(shù)據(jù)庫(kù)操作
創(chuàng)建數(shù)據(jù)庫(kù)
create database 數(shù)據(jù)庫(kù)名 charset=utf8;
刪除數(shù)據(jù)庫(kù)
drop database 數(shù)據(jù)庫(kù)名;
切換數(shù)據(jù)庫(kù)
use 數(shù)據(jù)庫(kù)名;
查看當(dāng)前選擇的數(shù)據(jù)庫(kù)
select database();
表操作
查看當(dāng)前數(shù)據(jù)庫(kù)中所有表
show tables;
創(chuàng)建表
auto_incremeaa表示自動(dòng)增長(zhǎng)
修改表
alter table 表名 add|change|drop 列名 類型;
如:alter table students add birthday datetime;
刪除表
drop table 表名;
查看表結(jié)構(gòu)
desc 表名;
更改表名稱
rename table 原表名 to 新表名;
查看表的創(chuàng)建語(yǔ)句
show create table '表名';
數(shù)據(jù)操作
查詢
select * from 表名
增加
全列插入:insert into 表名 values(...)
缺省插入:insert into 表名(列1,...) values(值1,...)
同時(shí)插入多條數(shù)據(jù):insert into 表名 values(...),(...)...;
或insert into 表名(列1,...) values(值1,...),(值1,...)...;
主鍵列是自動(dòng)增長(zhǎng)营曼,但是在全列插入時(shí)需要占位昔案,通常使用0,插入成功后以實(shí)際數(shù)據(jù)為準(zhǔn)
修改
update 表名 set 列1=值1,... where 條件
刪除
delete from 表名 where 條件
邏輯刪除电媳,本質(zhì)就是修改操作update
alter table students add isdelete bit default 0;
如果需要?jiǎng)h除則
update students isdelete=1 where ...;