數(shù)據(jù)庫 增刪改查

# show databases;//查看所有數(shù)據(jù)庫

# 退出命令

#exit,quit,\q

#創(chuàng)建數(shù)據(jù)庫

#create database mydatabase charset utf-8;

#創(chuàng)建關(guān)鍵字?jǐn)?shù)據(jù)庫

#create database `database` charset utf-8;

#告訴服務(wù)器當(dāng)前的中文字符集是什么

#set names gbk;

#創(chuàng)建中文數(shù)據(jù)庫

#create database 中國 charset utf-8;

#創(chuàng)建數(shù)據(jù)庫

#create database informationtest charset utf-8;

#查看以information_開始的數(shù)據(jù)庫(_需要被轉(zhuǎn)義)

# show databases like `information\_%`;

# show databases like `information_%`; 相當(dāng)于information%

#查看數(shù)據(jù)庫的創(chuàng)建語句

#show create database mydatabase;

# show create database `database`;

# 修改數(shù)據(jù)庫informationtest的字符集

# alter database informationtest charset GBK;

# 刪除數(shù)據(jù)庫

# drop database informationtest;

# 創(chuàng)建表

# create table if not exists mydatabase.student(

# 顯式地將student表放到mydatabase數(shù)據(jù)庫下

# name varchar(10),

# gender varchar(10),

# number varchar(10),

# age int

# )charset utf-8;

# 創(chuàng)建數(shù)據(jù)庫

# 進(jìn)入數(shù)據(jù)庫

# use mydatabase;

# 創(chuàng)建表

# create table class(

# name varchar(10),

# room varchar(10),

# )charset utf-8;

# 查看所有表

# show tables;

# 查看以s結(jié)尾的表

# show table like `%s`;

# 查看表的創(chuàng)建語句

# show create table student;

# show create table student\g

# show create table student\G? 將查到的結(jié)構(gòu)旋轉(zhuǎn)90度變成縱向

# 查看表結(jié)構(gòu)

# desc class;

# describe class;

# show columns from class;

# 重命名表(student表 -> my_student)

# rename table student to my_student;

# 修改表選項(xiàng):字符集

# alter table my_student charset = GBK;

# 給學(xué)生表添加ID,放到第一個(gè)位置

# alter table my_student

# add column id int

# first;

# 將學(xué)生表中的number學(xué)號(hào)字段變成固定長(zhǎng)度,且放到第二位(id之后)

# alter table my_student modify number char(10) after id;

# 修改學(xué)生表中的阿gender字段為sex

# alter table my_student change genter sex varchar(10);

# 刪除學(xué)生表中的age年齡字段

# alter table my_student drop age;

# 刪除數(shù)據(jù)表

# drop table class;

# 插入數(shù)據(jù)

# insert into my_student values

# (1,'bc20190001','Jim','male'),

# (2,'bc20190002','Lily','female');

# 插入數(shù)據(jù):指定文字列表

# insert into my_student(number,sex,name,id) values

# ('bc20190003','male','Tom',3),

# ('bc20190004','female','Lucy',4);

# 查看所有數(shù)據(jù)

# select * from my_student;

# 查看指定字段,指定條件的數(shù)據(jù)

# 查看滿足id為1的學(xué)生信息

# select id,number,sex,name from my_student where id=1;

# 更新數(shù)據(jù)

# update my_student set sex='female' where name='Jim';

# 刪除數(shù)據(jù)

# delete from my_student [where條件];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容