【正文】
什么是 事務(wù)(transaction) 所謂事務(wù),它是一個(gè)操作序列。 from user inner join(cases inner join goods on =) on =。, as 39。, as 39。 alter view case_view as select as 39。 修改視圖:alter view viewname as SQL。創(chuàng)建時(shí),應(yīng)將名稱指定為 mysqlcreate view as select *from t。 注意點(diǎn): 視圖屬于數(shù)據(jù)庫,在默認(rèn)情況下,將在當(dāng)前數(shù)據(jù)庫創(chuàng)建新視圖。物品名稱39。顧客姓名39。訂單編號39。 left join 以左邊的表查詢?yōu)橹? right join 以右邊的表查詢?yōu)橹? 示例: student left join school 那么student就為左表。通常左連接和右連接顯示的內(nèi)容是一樣的。當(dāng)滿足條件時(shí)。 查詢出:學(xué)生的編號,學(xué)生姓名 ,學(xué)生學(xué)校 select , from student left join school on =。 左連接:顯示sql語句中l(wèi)eft join 左邊表中的所有記錄,即使在left join 右邊的表中沒有滿足連接條件的數(shù)據(jù)也被顯示?;? select , from (cases inner join user on =) inner join goods on =。一個(gè)表引用還被稱為 查詢顯示:訂單編號,顧客姓名,物品名稱 select , from cases,user,goods where = and =。 第三范式:要求非主鍵列互不依賴 第四范式:禁止主鍵列和非主鍵列一對多關(guān)系不受 約束 第五 范式 :將表分割成盡可能 小的塊,為了排除在表中所有的冗余 MYSQL的聚合函數(shù) 最大值 找出EQ最高的學(xué)生 select name ,eq from student where eq=(select max(EQ)from student); SELECT MAX(article) AS article FROM shop。一旦創(chuàng)建 ,主鍵 無法改變,外鍵關(guān)聯(lián)一個(gè)表的主鍵。那么通常用‘ER’圖來表示 實(shí)體之間的三種類型:1:1 1:N 或N :1 M:N 數(shù)據(jù)庫設(shè)計(jì)員確定的實(shí)體被轉(zhuǎn)換為表,而其屬性則成為相應(yīng) 表中的字段(列) 如何控制冗余數(shù)據(jù): 一般來說通過數(shù)據(jù)庫的范式理論 設(shè)計(jì)數(shù)據(jù)庫的范式來 控制冗余 共有五個(gè)范式,一般達(dá)到第三范式即可 第一范式:對于表中的每一行,必須且僅僅有唯一的行值,在一行中的每一列僅有唯一的值并且具有原子性 第二范式 :要求 非主鍵列是主鍵的子集,非 主鍵列活動必須完全依賴整個(gè)主鍵。,1)。 insert into student(name,schoolid) values(39。)。 insert into school(name) values(39。 use fordb?;? select , from student as a, school as b where =。 查詢所有學(xué)生檔案信息 只需顯示:學(xué)生姓名,年齡。 查詢出所有學(xué)生的檔案信息 select * from student,school where =。abc39。張三39。); 創(chuàng)建一個(gè)有合理約束的表 create table people(id int not null auto_increment,name varchar(20) not null,age int not null,sex char(2) not null,pcode varchar(50),tel varchar(50), varchar(50),primary key(id))。 insert into test(name)values(39。張安39。 insert into test valuse(1)。 主鍵約束(primary key)是一個(gè)字段或一組字段(組合鍵),用于唯一標(biāo)識表中的記錄,它可以 確保每個(gè)記錄是唯一的。)。 默認(rèn)約束(default) create table test(id int not null default39。 innodb 會報(bào)錯 ,myISAM 會整形默認(rèn)以0填充 唯一約束(UNIQUE) 不允許列中的數(shù)據(jù)重復(fù) create table test(id int,unique(id))。 約束定義了表級的強(qiáng)制規(guī)則、數(shù)據(jù)的完整性 非空約束(not null) create table test(id int not null)。 實(shí)現(xiàn)查詢記錄的分頁 select * from stu limit 0,3。 select count(distinct(sex)) from stu。 distinct 過濾查詢的重復(fù)型記錄,只顯示唯一的記錄 將學(xué)生性別過濾 select distinct(sex) from stu?;? select * from stu where age20 and name=39。 group by對于查詢出的數(shù)據(jù)結(jié)果進(jìn)行分類(分組) 將學(xué)生按性別進(jìn)行分類 select * from stu group by sex; 將學(xué)生按年齡進(jìn)行分類 select * from stu group by age; having 子查詢:對于where查詢出的結(jié)果再次進(jìn)行查詢 查找出年齡大于20歲學(xué)生,并且在其中找出姓名等于xxx的學(xué)生 select * from stu where age 20 having name=39。性別39。年齡39。姓名39。女39。 or和and查詢 or(滿足一個(gè)條件) and(都需要滿足) 查找學(xué)生EQ為80分或90分的學(xué)生 select * from stu where EQ=80 or EQ=90。zhangsan39。姓名,性別,年齡,課程 導(dǎo)出sql腳本mysqldump stu uroot p 查看表的結(jié)構(gòu)desc tablename 修改表中的數(shù)據(jù)update tablename set colname=value where條件 刪除數(shù)據(jù)delete from teacher where age=? 刪除表中所有數(shù)據(jù)delete from teacher; 刪除表drop table tablename 根據(jù)條件進(jìn)行過濾查找select *from tablename where 條件 查找出版社為“清華出版社”的所有書籍select *from books where pub=‘清華出版社’; 查找出庫存大于50的所有書籍select *from books where store50; 查找出“西游記”的庫存量select title,store from books where title=‘西游記’; SQL運(yùn)算符 大于 小于 =大于等于 =小于等于 !=,不等于 查看數(shù)據(jù)庫的信息\s mysql常用函數(shù) 查看數(shù)據(jù)庫版本select versin(); 計(jì)算機(jī)的時(shí)間是存在BIOS() 查看當(dāng)前數(shù)據(jù)庫的日期select current_date(); 查看當(dāng)前數(shù)據(jù)庫時(shí)間select now(); 查看當(dāng)前連接數(shù)據(jù)庫的用戶select user();localhost:代表是本機(jī) create table user(id int,name varchar(20),bir date,dea datetime)。練習(xí): amp。BLOB是一個(gè)能保存二進(jìn)制數(shù)據(jù)的大對象,區(qū)別是TEXT不區(qū)分大小寫,而BLOB區(qū)分大小寫。等待下一行,等待以單引號開始的字符串結(jié)束 如果你決定不想執(zhí)行正在輸入過程中的一個(gè)命令,輸入\c取消它 能夠以大小寫輸入關(guān)鍵詞,結(jié)果是等價(jià)的 基本的SQL語句 創(chuàng)建數(shù)據(jù)庫create