資料庫關聯查詢

2021-09-12 16:44:50 字數 1799 閱讀 4943

使用者授權,我們涉及到了三個物件

1、使用者名稱root 2、密碼 3、主機localhost

建立名字為qq的使用者

create user qq@localhost;

建立名字為anan使用者並新增密碼

create user anan@localhost identified by 「123」;

建立使用者允許遠端端登入

create user [email protected] identified by 「123」;允許10.10.10.100以anan登入mysql

create user anan@「10.10.10.%」 identified by 「123」; 允許10.10.10.0到10.10.10.255以anan登入mysql

create user [email protected]_ identified by 「123」;允許10.10.10.100到10.10.10.105以anan登入mysql

刪除使用者

drop user [email protected]

刪除使用者要帶上主機位址,避免有同名字不同主機位址的使用者出現錯刪。

常規許可權分五種

select 查詢許可權

insert 插入許可權

update 更新許可權

create 建立許可權

grant select on aa.bb to anan@localhost 將aa資料庫的bb表的查詢許可權授權給

以localhost登入的anan使用者。

grant insert on aa.bb to anan@localhost 將aa資料庫的bb表的插入許可權授權給

以localhost登入的anan使用者。

grant delete on aa.bb to anan@localhost將aa資料庫的bb表的刪除許可權授權給

以localhost登入的anan使用者。

grant update on aa.bb to anan@localhost將aa資料庫的bb表的更新許可權授權給

以localhost登入的anan使用者。

grant select(id,name) on aa.bb to anan@localhost 將bian資料庫的bb表的id和name

欄位的查詢許可權授權給localhost登入的anan使用者

grant select,insert,update,delete on aa.bb to anan@localhost 將aa資料庫的bb表的

增刪改查的許可權授權給以localhost登入的anan使用者

****

主鍵primary key:是乙個表裡的唯一標識,假如乙個表沒有主鍵,查詢是遍歷查詢,如果有主鍵,會以

平衡樹資料格式去找。

外來鍵foreign key:就是以表唯一欄位為內容的關聯字段,約束;定義的時候建立外來鍵

當前表要作為外來鍵的字段 references 要對應的表(對應表的字段)定義好的表新增外來鍵,外來鍵字段必須先存在。

1、inner join內關聯查詢

取左右兩表的交集

2、left join左關聯查詢

取左表的所有和左右兩表的交集

3、right join右關聯查詢

取右表的所有和左右兩表的交集

like向

select * from student where name like 「李%」

查詢所有 表student中, 名字中姓李的人;當"%李%"這樣查詢的話 名字中間帶「李」字的人也會被搜出

資料庫多表關聯查詢

本文主要列舉兩張和三張表來講述多表連線查詢。新建兩張表 表1 student 截圖如下 表2 course 截圖如下 此時這樣建表只是為了演示連線sql語句,當然實際開發中我們不會這樣建表,實際開發中這兩個表會有自己不同的主鍵。外連線可分為 左連線 右連線 完全外連線。1 左連線 left join...

資料庫多表查詢關聯查詢SQL語句

left join on 關鍵字會從左表那裡返回所有的行,即使在右表中沒有匹配的行。意思就是向左關聯某個表記錄,以左邊的那個表的記錄為基準,通過關聯條件,將關聯表的相關符合要求的記錄一起找出來,找出來的記錄條數就是左邊表的記錄數 具體用法如下 select column name s from ta...

九 MySql資料庫 關聯查詢(九)

1.1 交叉連線 笛卡爾乘積現象 交叉連線查詢 不推薦。產生笛卡爾乘積現象 4 4 16,有些是重覆記錄 select empname,deptname from employee,dept 笛卡爾乘積現象 假如employee有4條記錄,dept有4條記錄,那麼上面的sql查詢結果,則為 4 4 ...