版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
123什么是數(shù)據(jù)庫?就是一個文件系統(tǒng),通過標(biāo)準(zhǔn)SQL語言操作文件系統(tǒng)中數(shù) 何平臺,windowS.LINUX。PHP完全開源免費(fèi),自從mysql被oracle收購后,從6.0開始出現(xiàn)版本。SYBASE中等規(guī)模數(shù)據(jù)庫,。PowerDesigner數(shù)據(jù)庫建模工具SQLServer微軟公司數(shù)據(jù)庫產(chǎn)品中等規(guī)模數(shù)據(jù)庫操作系統(tǒng)要求是windows結(jié)合.netJavaMySQL、Oracle、DB2SQLmysqlmysql1、知道m(xù)ysql的安 在mysql的安 。找到my.ini文件找到datadir并且記錄路徑。(mysql的數(shù)據(jù)文件 4mysql5、刪除mysql的安 mysqlmysqlpath:;C:\ProgramFiles\MySQL\MySQLServer按照完成之后,在cmdmysql–urootmysql?在命令行中輸入,mysqldskip-grant-tables,啟動服務(wù)器,啟動服務(wù)器光標(biāo)不懂,一定新打開cmd,輸入mysql-uroot- 這個時候是不需要的useupdateusersetpassword=password('新')whereuser='root';flushprivileges;關(guān)閉兩個cmdmysqldmysqlmysql–urootsqlSQLStructuredQueryLanguage(結(jié)構(gòu)化查詢語言)的縮寫。SQL是專為數(shù)據(jù)庫而建立的操作命令集。SQL功能強(qiáng)大、簡單易學(xué)、使用方便,已經(jīng)成為了數(shù)據(jù)庫操作的基礎(chǔ),并且現(xiàn)SQL。inta=10;intb=intsum=SQL的語言能力,各廠商增強(qiáng)了過程性語言的特征OraclePL/SQL過程性處理能力SQLServer、SybaseT-SQL是用來存取關(guān)系數(shù)據(jù)庫的語言,具有查詢、、定義和控制關(guān)系型數(shù)據(jù)庫的四方DDL(數(shù)據(jù)定義語言DataDefinitioncreatedrop DataManipulation如update,insert,deleteDCL(數(shù)據(jù)控制語言DataControlDQL(數(shù)據(jù)查詢語言 DataQueryLanguage3、表記錄 sql1:createdatabase數(shù)據(jù)庫名。----;---mysql(安裝數(shù)據(jù)庫時候指定的2:createdatabasecharacterset‘字符集’如果指定字符集是 utf-8是錯誤滴(mysql不認(rèn)識UTF-8)utf8mydb2如何查看一個數(shù)據(jù)庫的字符集:showcreatedatabase數(shù)據(jù)庫名;查詢某個數(shù)據(jù)庫的字符集,3:createdatabasecharactersetcollate‘比較規(guī)則’。。1、show 2showcreatedatabase(也可以查看到字符;dropdatabase數(shù)據(jù)庫名;alterdatabasecharacterset字符集mydb2createdatabaseshowshowcreate dropdatabasealterdatabasecharactersetuse數(shù)據(jù)庫名 select sql注意:創(chuàng)建表的時候,一定要切換到某一個具體的數(shù)據(jù)庫:切換數(shù)據(jù)庫的方式use數(shù)據(jù)庫createtable表名列名數(shù)據(jù)類型 use字符串型:如果某一個字段,定義了字符串類型。需要為這個字段指定長度。列名varchar(長度) varchar(長度)假設(shè)說定義了20個長度namevarchar(20) 。name存貯數(shù)據(jù)的長度是20以內(nèi)的。存了:lisi:表示4個長度,zhangsan:8個長度 char(20)lisi20zhangsan20。問題:char的性能好。varchar()BLOB、TEXT(文件 *tinyblob 255blob mediumblobmediumtext16MBlongbloblongtext 整形:TINYINT、SMALLINT、INT、BIGINT short,int,longtrue1或者falsechar(1)0表示false,1date:日期---- createcreatetableemployee(idint,namevarchar(20),gendervarchar(10),birthdaydate,entry_datedate, salarydouble,resumetextshowtables;desc主鍵約束:primaryint類型的,我們可以給他設(shè)置自動增長,auto_increment(長度)primarykey 列名類型(長度)unique,1、唯一約束可以是空(null)非空約束:notnull。不允許為空。列明類型(長度)notnull,createtableidintprimarykeyauto_increment,namevarchar(20)notnullunique,gendervarchar(10)notnull,birthdaydate,entry_datedate,jobsalarydoublenotnull,resumetextidnamesalarygender1altertableadd(長度)altertablemodify(長度)約束;altertablechange(長度)約束altertabledrop5renametabletoaltertablecharactersetgendernamealtertableuserchangecolumnnameusernamedroptable表名;desc表名:查看表的列的信息(查看表結(jié)構(gòu)showtables:showcreatetable創(chuàng)建數(shù)據(jù)庫:createdatabase修改數(shù)據(jù)庫:alterdatabasecharacterset字符集刪除數(shù)據(jù)庫:dropdatabase查看數(shù)據(jù)庫:showdatabases;showcreatedatabase數(shù)據(jù)庫名;創(chuàng)建數(shù)據(jù)表:createtable表名((長度)修改數(shù)據(jù)表:altertable(add|drop|modify|change)列名類型(長度)刪除數(shù)據(jù)表:droptable表名;showcreatetabledesc針對表記錄:CRUDinsert語 數(shù)據(jù)記錄的增數(shù)據(jù)記錄位置:表insertinto表名(values();1null。4、date‘yyyyMMddyyyy-MM-dd’,’yyyy/MM/dd’select*from---練習(xí):新建employeeinsertintoemployee(id,name,gender,birthday ','manager',0.5 cmdgbkmysql中編碼集大體上分為兩部分。server、system、database。connection是連接數(shù)據(jù)庫的字符集設(shè)置類型,如果程序沒有指明連接數(shù)據(jù)庫使用的字符集類showvariableslikesetnamesgbk*mysql/my.inimy.ini在mysql的安 [mysql][mysqld][mysql]后字符集default-character- insertinto表名(values()insertintovalues(值,值,值,值descnull。insertintoemployee2(id,name,gender,salary)values(null,'ww','male',2000);insertintoemployee2(name,gender,salary)values('zs','male',2000);updateupdateset列名=值,列名=where=>< where,會把表中的所有行的對應(yīng)的列全部修改。將為’zs’的員工薪水修改為3000元將為’ls’的員工薪水修改為4000元,job改為ccc。wangwu1000元。updateemployee2set將為’zs’的員工薪水修改為3000元updateemployee2setsalary=3000where將為’ls’的員工薪水修改為4000元,job改為ccc。updateemployee2setsalary=4000,job='cccwherename='ls';ww1000元。updateemployee2set wheredelete語 deletefromwherewhere,刪除表中的所有的記錄。delete刪除的是行。不能刪除列。deletefromemployee2wherename='zs';deletefromtruncatetable表名;---truncatetable表名:執(zhí)行方式:deletetruncatetabledeletetruncatetable同?truncatedelete*truncate例如轉(zhuǎn)賬。a轉(zhuǎn)b100。a-truncateDDL,delete屬于DML========DMLSQLSQL執(zhí)行前狀態(tài)。starttransaction commit提 select1、select*from2、selectfrom表名3、selectdistinctfromdistinctcreatetableidintprimarykeyauto_increment,namevarchar(20)notnull,mathdouble,englishdoubleinsertintoexamvalues(null,'',85,76,70);insertintoexamvalues(null,'',70,75,70);insertintoexamvalues(null,'',90,65,95);insertintoexamvalues(null,'',97,50,50);insertintoexamvalues(null,'',90,89,80);insertintoexamvalues(null,'',90,67,65); distinct列名a,列名a重復(fù)的同時,b select運(yùn)算 列名+-*/fromas關(guān)鍵字起別名寫法 as別selectasfromasselectfromselectname englishfrom問:列出兩個字段。那個兩個字段的內(nèi)容。name10分特長分。selectwhereselect*fromwhereselectwhereselect列名+列名as from表名where條查詢?yōu)閄XX的學(xué)生成901、這里的不等于是 等于是2、between值1and值2,相當(dāng)于>=值1 <=值前面的值要比后面的小。1<3、in(值,值,值)ain(1,2,3,4)等價于a=1ora=2ora=3or4、like%表示的任意的字符(沒有長度限制)_表示的占位符(一個下劃線表示一個namelike張%’---namelike‘張 5、is 在sql中a=null不允許。提供aisnull。 isnot80-90之間的同學(xué)。89,75,91的同學(xué)。查詢數(shù)學(xué)分>80并且語文分>80的同學(xué)。查詢數(shù)學(xué)分>80>80的同學(xué)。為select*fromexamwhere 90selectselect*fromexamwhereenglish>select*fromexamwhere +math+english>200;80-908090select*fromexamwhereenglishbetween80and90;select*fromexamwhereenglish=80andenglish90;查詢數(shù)學(xué)分?jǐn)?shù)為89,75,91的同學(xué)。select*fromexamwheremathselect*fromexamwheremath=89ormath=75orinsertinto insertinto)select*fromexamwherenamelike劉select*fromexamwherenamelike'劉select*fromexamwheremath>80查詢數(shù)學(xué)分>80>80select*fromexamwheremath>80nullifnull(值,默認(rèn)值)nullnull,返回第selectorderby(desc|asc(desc|asc123進(jìn)行排序輸出。 ….from…where…orderbyorderbyaabab1112 orderbyaasc,b11122332asc升序。select*fromexamorderbymath;select*fromexamorderbymathasc;--selectname, fromexamorder select*fromexam namelike'劉%'order select語句中使用函數(shù)作用:統(tǒng)計。統(tǒng)計:統(tǒng)計班級的平均分。一個函數(shù)從多個輸入行中計算出一個結(jié)果。比如,我們有在一個行集合上計count(數(shù)目, ,count函數(shù)--count(列名)null,不做統(tǒng)計selectcount(列名)from表名selectcount(*)fromselectcount(id)from90selectselectcount(id)fromexamwhereselectcount(id)fromexam+math+english>sumsum(列名統(tǒng)計該列的所有的值的和。sumnullselectsum(列名)from表名whereavg函數(shù)--avg(列名)----求該列的平均值----avg里面的null統(tǒng)selectavg(列名fromwhereselectselectavg(math)fromselectavg( ,0)+ifnull(math,0)+ifnull(english,0))frommax/min最大值/max(列/min(列)selectmax(),minfrom---nullselectgroupbygroupby注意:通常select的內(nèi)容,被分組的列,以及函數(shù)groupbyhaving條件createtableorders(idint,productvarchar(20),pricefloatinsertintoorders(id,product,price)values(1,'電視',900);insertintoorders(id,product,pricevalues(2,'洗衣機(jī)',100);insertintoorders(id,product,price)values(3,'洗衣粉',90);insertintoorders(id,product,price)values(4,'桔子',9);insertintoorders(id,product,price)values(5,'洗衣粉',90);wherehaving1、having2、wherehavinghavingwhere例如having中的函數(shù)where是在分組之前進(jìn)行過濾having分組之后進(jìn)行運(yùn)算的條件是不能寫在where中的。 from1 where2groupby3having4orderby5注意:通常我們把having
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 嗆奶的課件教學(xué)課件
- 遼寧省2025秋九年級英語全冊Unit10You'resupposedtoshakehands課時5SectionB(2a-2e)課件新版人教新目標(biāo)版
- 2025年塑料家具項目發(fā)展計劃
- 黃疸的飲食調(diào)整與護(hù)理
- VSD護(hù)理技巧分享
- 疝氣護(hù)理中的疼痛評估與處理
- 耳鳴的藥物治療與非藥物治療
- 護(hù)理人文素養(yǎng)與手術(shù)室護(hù)理
- 員工培訓(xùn)課件app
- 護(hù)理差錯防范:培訓(xùn)與教育策略
- GB/T 6075.3-2011機(jī)械振動在非旋轉(zhuǎn)部件上測量評價機(jī)器的振動第3部分:額定功率大于15 kW額定轉(zhuǎn)速在120 r/min至15 000 r/min之間的在現(xiàn)場測量的工業(yè)機(jī)器
- GB/T 38591-2020建筑抗震韌性評價標(biāo)準(zhǔn)
- GB/T 34107-2017軌道交通車輛制動系統(tǒng)用精密不銹鋼無縫鋼管
- GB/T 31402-2015塑料塑料表面抗菌性能試驗方法
- GB/T 20969.3-2007特殊環(huán)境條件高原機(jī)械第3部分:高原型工程機(jī)械選型、驗收規(guī)范
- 最新-脂肪性肝病課件
- 眼科OCT異常圖譜解讀
- DB11- 996-2013-城鄉(xiāng)規(guī)劃用地分類標(biāo)準(zhǔn)-(高清有效)
- 風(fēng)光互補(bǔ)系統(tǒng)實(shí)驗(圣威科技)王鑫
- 1-院前急救風(fēng)險管理
- 古典園林分析之郭莊講解課件
評論
0/150
提交評論