做網(wǎng)站公司哪個(gè)好百度免費(fèi)推廣平臺(tái)
目錄
1、查詢(xún)
2、創(chuàng)建
3、修改
4、刪除
1、查詢(xún)
1、查詢(xún)所有數(shù)據(jù)庫(kù)
show databases;
2、查詢(xún)當(dāng)前數(shù)據(jù)庫(kù)
select database();
3、查詢(xún)當(dāng)前數(shù)據(jù)庫(kù)中所有的表(需要先進(jìn)入這個(gè)數(shù)據(jù)庫(kù))
use d1; show tables;
4、查詢(xún)表結(jié)構(gòu)
desc users;
5、查詢(xún)指定表的建表語(yǔ)句
show create table users;
2、創(chuàng)建
1、創(chuàng)建數(shù)據(jù)庫(kù)
create database d1;
2、判斷數(shù)據(jù)庫(kù)是否存在,不存在再創(chuàng)建
create database if not exists d1;
3、設(shè)置字符集
create database d1 default charset utf8mb4;
4、創(chuàng)建表
create table emp(id int comment '編號(hào)',workno varchar(10) comment '工號(hào)',name varchar(10) comment '姓名',gender char(1) comment '性別',age tinyint unsigned comment '年齡',idcard char(18) comment '身份證號(hào)',entrydate date comment '入職時(shí)間' ) comment '員工表';
5、如果表不存在再創(chuàng)建
create table if not exists emp(... ) comment '員工表';
3、修改
1、給表添加字段
alter table emp add hobby char(2) comment '愛(ài)好';
?2、修改某一個(gè)字段的數(shù)據(jù)類(lèi)型
alter table emp modify hobby int;
3、修改某一個(gè)字段的字段名和字段類(lèi)型
alter table emp change hobby hobby2 char(10) comment '修改了字段名';
4、修改表名
alter table emp rename to emp1;
4、刪除
1、刪除表(存在則刪除)
drop table if exists emp;
?2、刪除指定表 并重新創(chuàng)建該表;(會(huì)刪除表中的所有數(shù)據(jù))
truncate table emp;
3、刪除字段
alter table emp drop name;