日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql命令巧记_MYSQL常用命令大全(三)【值得收藏】

發布時間:2025/3/20 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql命令巧记_MYSQL常用命令大全(三)【值得收藏】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【友情提示】你必須首先登錄到MySQL中,以下操作都是在MySQL的提示符下進行的且每個命令以分號結束。

7、下面的語句在mysql環境在執行

顯示用戶擁有權限的數據庫 show databases;

切換到staffer數據庫 use staffer;

顯示當前數據庫中有權限的表 show tables;

顯示表staffer的結構 desc staffer;

8、創建測試環境

1)創建數據庫staffer

mysql> create database staffer

2)創建表staffer,department,position,depart_pos

create table s_position(

id int not null auto_increment,

name varchar(20) not null default '經理', #設定默認值

description varchar(100),

primary key PK_positon (id) #設定主鍵

);

create table department(

id int not null auto_increment,

name varchar(20) not null default '系統部', #設定默認值

description varchar(100),

primary key PK_department (id) #設定主鍵

);

create table depart_pos(

department_id int not null,

position_id int not null,

primary key PK_depart_pos (department_id,position_id) #設定復和主鍵

);

create table staffer(

id int not null auto_increment primary key, #設定主鍵

name varchar(20) not null default '無名氏', #設定默認值

department_id int not null,

position_id int not null,

unique (department_id,position_id) #設定唯一值

);

3)刪除

mysql>

drop table depart_pos;

drop table department;

drop table s_position;

drop table staffer;

drop database staffer;

9、修改結構

mysql>

#表position增加列test

alter table position add(test char(10));

#表position修改列test

alter table position modify test char(20) not null;

#表position修改列test默認值

alter table position alter test set default 'system';

#表position去掉test默認值

alter table position alter test drop default;

#表position去掉列test

alter table position drop column test;

#表depart_pos刪除主鍵

alter table depart_pos drop primary key;

#表depart_pos增加主鍵

alter table depart_pos add primary key PK_depart_pos (department_id,position_id);

10、操作數據

#插入表department

insert into department(name,description) values('系統部','系統部');

insert into department(name,description) values('公關部','公關部');

insert into department(name,description) values('客服部','客服部');

insert into department(name,description) values('財務部','財務部');

insert into department(name,description) values('測試部','測試部');

#插入表s_position

insert into s_position(name,description) values('總監','總監');

insert into s_position(name,description) values('經理','經理');

insert into s_position(name,description) values('普通員工','普通員工');

#插入表depart_pos

insert into depart_pos(department_id,position_id)

select a.id department_id,b.id postion_id

from department a,s_position b;

#插入表staffer

insert into staffer(name,department_id,position_id) values('陳達治',1,1);

insert into staffer(name,department_id,position_id) values('李文賓',1,2);

insert into staffer(name,department_id,position_id) values('馬佳',1,3);

insert into staffer(name,department_id,position_id) values('亢志強',5,1);

insert into staffer(name,department_id,position_id) values('楊玉茹',4,1);

11、查詢及刪除操作

#顯示系統部的人員和職位

select a.name,b.name department_name,c.name position_name

from staffer a,department b,s_position c

where a.department_id=b.id and a.position_id=c.id and b.name='系統部';

#顯示系統部的人數

select count(*) from staffer a,department b

where a.department_id=b.id and b.name='系統部'

#顯示各部門的人數

select count(*) cou,b.name

from staffer a,department b

where a.department_id=b.id

group by b.name;

#刪除客服部

delete from department where name='客服部';

#將財務部修改為財務一部

update department set name='財務一部' where name='財務部';

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的mysql命令巧记_MYSQL常用命令大全(三)【值得收藏】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。