use mysql; ==》进入到MySQL数据库\r","marks":[]}]}],"state":{}},{"type":"block","id":"o8kJ-1659534012558","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ZUi2-1659534012559","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"bBys-1659534012560","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6uu8-1659534012561","leaves":[{"text":"11)mysql>show databases; ==》展示所有的数据库 (注意数据库操作sql语句需要接英文分号)\r","marks":[]}]}],"state":{}},{"type":"block","id":"kgwf-1659534012562","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"EG8Z-1659534012563","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"nnVr-1659534012564","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"zVA8-1659534012565","leaves":[{"text":"12)mysql>exit; ==》退出MySQL数据库 或者按ctrl+c\r","marks":[]}]}],"state":{}},{"type":"block","id":"It72-1659534012566","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"YXQJ-1659534012567","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"1aj1-1659534012568","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"f12i-1659534012569","leaves":[{"text":"13)create database +库名\r","marks":[]}]}],"state":{}},{"type":"block","id":"39ko-1659534012570","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"IgO5-1659534012571","leaves":[{"text":"mysql>create database dcs9; ==》创建一个dcs9这个数据库\r","marks":[]}]}],"state":{}},{"type":"block","id":"KgIc-1659534012572","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"yI7z-1659534012573","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"6oPZ-1659534012574","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"rKcF-1659534012575","leaves":[{"text":"14)drop database +库名\r","marks":[]}]}],"state":{}},{"type":"block","id":"HSnW-1659534012576","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"uKIg-1659534012577","leaves":[{"text":"mysql>drop database dcs9; ==》删除dcs9这个数据库\r","marks":[]}]}],"state":{}},{"type":"block","id":"0Uiu-1659534012578","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"uYpU-1659534012579","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"ZSPl-1659534012580","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"YgTl-1659534012581","leaves":[{"text":"15) use dcs9; ==》进入到dcs9这个库\r","marks":[]}]}],"state":{}},{"type":"block","id":"H39P-1659534012582","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"7r3P-1659534012583","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"ChCr-1659534012584","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"i1m3-1659534012585","leaves":[{"text":"16)select database(); ==》查看当前在哪个库\r","marks":[]}]}],"state":{}},{"type":"block","id":"Ky8T-1659534012586","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"bkef-1659534012587","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"2obR-1659534012588","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Dtbp-1659534012589","leaves":[{"text":"17)create table +表名(字段1 数据类型 约束,字段2 数据类型 约束,字段3 数据类型 约束...);\r","marks":[]}]}],"state":{}},{"type":"block","id":"MWWc-1659534012590","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"2Kr2-1659534012591","leaves":[{"text":"mysql>create table dcs(id int(10) primary key auto_increment,score float(10,2) \r","marks":[]}]}],"state":{}},{"type":"block","id":"1Ewq-1659534012592","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"B1Uz-1659534012593","leaves":[{"text":"not null,name varchar(10),phone bigint(10) default 13977778888,time date);\r","marks":[]}]}],"state":{}},{"type":"block","id":"FTTS-1659534012594","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"l5V3-1659534012595","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"FgDy-1659534012597","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"fnWU-1659534012598","leaves":[{"text":"18)show tables; ==》展示当前库下所有的表\r","marks":[]}]}],"state":{}},{"type":"block","id":"1NOZ-1659534012599","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"1aEd-1659534012600","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"ut4W-1659534012601","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"8vMv-1659534012602","leaves":[{"text":"19)mysql> desc dcs; ==》查看dcs这个表的表结构(desc ==>description)\r","marks":[]}]}],"state":{}},{"type":"block","id":"SfF8-1659534012603","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Awb-1659534012604","leaves":[{"text":"+-------+-------------+------+-----+-------------+----------------+\r","marks":[]}]}],"state":{}},{"type":"block","id":"AFIb-1659534012605","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"gFtN-1659534012606","leaves":[{"text":"| Field | Type | Null | Key | Default | Extra |\r","marks":[]}]}],"state":{}},{"type":"block","id":"ZQ9i-1659534012607","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"EN4L-1659534012608","leaves":[{"text":"+-------+-------------+------+-----+-------------+----------------+\r","marks":[]}]}],"state":{}},{"type":"block","id":"ggXG-1659534012609","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"G4VD-1659534012610","leaves":[{"text":"| id | int(10) | NO | PRI | NULL | auto_increment |\r","marks":[]}]}],"state":{}},{"type":"block","id":"2PsK-1659534012611","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"crGX-1659534012612","leaves":[{"text":"| score | float(10,2) | NO | | NULL | |\r","marks":[]}]}],"state":{}},{"type":"block","id":"s1yR-1659534012613","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"QlY1-1659534012614","leaves":[{"text":"| name | varchar(10) | YES | | NULL | |\r","marks":[]}]}],"state":{}},{"type":"block","id":"cixl-1659534012615","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vUGz-1659534012616","leaves":[{"text":"| phone | bigint(10) | YES | | 13977778888 | |\r","marks":[]}]}],"state":{}},{"type":"block","id":"jkMV-1659534012617","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"E3pX-1659534012618","leaves":[{"text":"| time | date | YES | | NULL | |\r","marks":[]}]}],"state":{}},{"type":"block","id":"vtzD-1659534012619","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"3jAl-1659534012620","leaves":[{"text":"+-------+-------------+------+-----+-------------+----------------+\r","marks":[]}]}],"state":{}},{"type":"block","id":"TJfb-1659534012621","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"CXAQ-1659534012622","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"WCS7-1659534012623","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Ukf8-1659534012624","leaves":[{"text":"field ==》字段\r","marks":[]}]}],"state":{}},{"type":"block","id":"FUkQ-1659534012625","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"EPCi-1659534012626","leaves":[{"text":"type ==》类型\r","marks":[]}]}],"state":{}},{"type":"block","id":"LIjs-1659534012627","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"kMYn-1659534012628","leaves":[{"text":"null ==》是否可以为空\r","marks":[]}]}],"state":{}},{"type":"block","id":"1eMG-1659534012629","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"YVz3-1659534012630","leaves":[{"text":"key ==》primary key 主键\r","marks":[]}]}],"state":{}},{"type":"block","id":"Fsel-1659534012631","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"lx4F-1659534012632","leaves":[{"text":"default ==》默认值\r","marks":[]}]}],"state":{}},{"type":"block","id":"jYEG-1659534012633","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"jIsB-1659534012634","leaves":[{"text":"extra ==》额外备注\r","marks":[]}]}],"state":{}},{"type":"block","id":"EWO2-1659534012635","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vntc-1659534012636","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"FHyD-1659534012637","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"pPte-1659534012638","leaves":[{"text":"数据库中常见的数据类型【重点】\r","marks":[]}]}],"state":{}},{"type":"block","id":"BsS7-1659534012639","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"57GU-1659534012640","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"dVah-1659534012641","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"QAbA-1659534012642","leaves":[{"text":"数值型\r","marks":[]}]}],"state":{}},{"type":"block","id":"q5xJ-1659534012643","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"DtJS-1659534012644","leaves":[{"text":"int ==》整型 最大值2147483647\r","marks":[]}]}],"state":{}},{"type":"block","id":"bu7i-1659534012645","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wJlX-1659534012646","leaves":[{"text":"bigint ==》整型 手机号 超过int 就只能用bigint\r","marks":[]}]}],"state":{}},{"type":"block","id":"oKLi-1659534012647","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"yWzb-1659534012648","leaves":[{"text":"float ==》浮点型 float(10,2) 整数部分和小数部分加起来是总共10位,2是精确位数,2位小数点\r","marks":[]}]}],"state":{}},{"type":"block","id":"aIL5-1659534012649","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"3S4r-1659534012650","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"8Etz-1659534012651","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"r4gs-1659534012652","leaves":[{"text":"文本型(varchar 和char 存储数据时需要单引号或者双引号)\r","marks":[]}]}],"state":{}},{"type":"block","id":"eDq9-1659534012653","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"zhLg-1659534012654","leaves":[{"text":"区别:\r","marks":[]}]}],"state":{}},{"type":"block","id":"5Vtq-1659534012655","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"mNsa-1659534012656","leaves":[{"text":"1)char 的长度固定的,varchar 是可以变化的\r","marks":[]}]}],"state":{}},{"type":"block","id":"qJG3-1659534012657","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"RJij-1659534012658","leaves":[{"text":"char(10) 和varchar(10)同样存储‘abc’ ,对于char存储三个字节,还有7个回用\r","marks":[]}]}],"state":{}},{"type":"block","id":"JMJn-1659534012659","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wRoJ-1659534012660","leaves":[{"text":"空格补上,varchar 存储的只有三个字节,其他7个不会用空格补上\r","marks":[]}]}],"state":{}},{"type":"block","id":"Fjtz-1659534012661","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ANXu-1659534012662","leaves":[{"text":"2)char 的效率笔varchar要高\r","marks":[]}]}],"state":{}},{"type":"block","id":"F23N-1659534012663","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"FCFW-1659534012665","leaves":[{"text":"3)varchar 比char节省空间\r","marks":[]}]}],"state":{}},{"type":"block","id":"eiMH-1659534012666","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"DZeh-1659534012667","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"6Ziy-1659534012668","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"NVRj-1659534012669","leaves":[{"text":"日期型 存储数据时需要单引号或者双引号\r","marks":[]}]}],"state":{}},{"type":"block","id":"jkE4-1659534012670","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"WViQ-1659534012671","leaves":[{"text":"date ==>\"2022-8-3\"\r","marks":[]}]}],"state":{}},{"type":"block","id":"k82K-1659534012672","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6gEq-1659534012673","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"wiax-1659534012674","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"5SmR-1659534012675","leaves":[{"text":"数据库有哪些约束【重点】","marks":[{"type":"backgroundColor","value":"#FF0001"}]},{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"kuTE-1659534012676","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6viN-1659534012677","leaves":[{"text":"not null ==》非空约束\r","marks":[]}]}],"state":{}},{"type":"block","id":"jhGh-1659534012678","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6MWQ-1659534012679","leaves":[{"text":"primary key ==》主键约束 唯一的,不能重复,一个表只有一个主键 如身份证\r","marks":[]}]}],"state":{}},{"type":"block","id":"UVcB-1659534012680","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Yowx-1659534012681","leaves":[{"text":"default ==>默认值约束,不给新值就是用默认\r","marks":[]}]}],"state":{}},{"type":"block","id":"yCIR-1659534012682","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"L6LD-1659534012683","leaves":[{"text":"auto_increment ==》自增长约束,不给值时,默认加一,在这个一定要和主键一起使用\r","marks":[]}]}],"state":{}},{"type":"block","id":"jQqU-1659534012684","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"luGy-1659534012685","leaves":[{"text":"foreign key ==》外键约束 表与表之间的约束\r","marks":[]}]}],"state":{}},{"type":"block","id":"FCBV-1659534012686","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ZjTC-1659534012687","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"mAek-1659534012688","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"xSqO-1659534012689","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"WMRQ-1659534012690","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"FeAj-1659534012691","leaves":[{"text":"8","marks":[]},{"text":"、修改表结构 【重点】","marks":[{"type":"backgroundColor","value":"#FF0001"}]},{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"cUJM-1659534012692","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"q3Ad-1659534012693","leaves":[{"text":"1.查看表结构 desc +表名 显示字段名称,数据类型,约束,备注 \r","marks":[]}]}],"state":{}},{"type":"block","id":"MLro-1659534012694","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0Fbe-1659534012695","leaves":[{"text":"desc dcs ==》修改表结构\r","marks":[]}]}],"state":{}},{"type":"block","id":"mlic-1659534012696","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Bzg-1659534012697","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"akjA-1659534012698","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"BIwr-1659534012699","leaves":[{"text":"2.修改表名alter table +表名 rename + 新表名 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Wsn6-1659534012700","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"fmiM-1659534012701","leaves":[{"text":"alter table dcs rename dcs1 ==》把dcs这个表改名为dcs1\r","marks":[]}]}],"state":{}},{"type":"block","id":"vY01-1659534012702","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"AsOZ-1659534012703","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"ybLs-1659534012705","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"75DQ-1659534012706","leaves":[{"text":"3.修改表字段 alter table +表名 change +原字段名 +新字段名 数据类型,约束\r","marks":[]}]}],"state":{}},{"type":"block","id":"kG7S-1659534012707","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6v1m-1659534012708","leaves":[{"text":"alter table dcs change id sid int(10); ==》把id字段改名为sid字段并且取消自增长\r","marks":[]}]}],"state":{}},{"type":"block","id":"mFLs-1659534012709","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"D1La-1659534012710","leaves":[{"text":"alter table dcs change sid id int(10); ==》把sid字段改名位id字段\r","marks":[]}]}],"state":{}},{"type":"block","id":"DcFn-1659534012711","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"4Bh2-1659534012712","leaves":[{"text":"alter table dcs change id id int(10) auto_increment; ==》不改变id字段加上自增长\r","marks":[]}]}],"state":{}},{"type":"block","id":"kz6A-1659534012713","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"x8YL-1659534012714","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"AuY1-1659534012715","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"UoJx-1659534012716","leaves":[{"text":"4.添加表字段,并放到第一个字段前 alter table +表名 add +字段名 数据类型 约束 first\r","marks":[]}]}],"state":{}},{"type":"block","id":"wXeP-1659534012717","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"DbnY-1659534012718","leaves":[{"text":"alter table dcs add class int(10) first; ==》添加一个字段放在最前面 \r","marks":[]}]}],"state":{}},{"type":"block","id":"rxAr-1659534012719","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"sIzT-1659534012720","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"SuSF-1659534012721","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"VjGa-1659534012722","leaves":[{"text":"5.添加表字段,并放到某个字段后 alter table +表名 add +字段名 数据类型 约束 after +字段名\r","marks":[]}]}],"state":{}},{"type":"block","id":"iAXl-1659534012723","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wAyY-1659534012724","leaves":[{"text":"alter table dcs add age int(10) after name; ==》添加一个字段放在name字段的后面\r","marks":[]}]}],"state":{}},{"type":"block","id":"nZzb-1659534012726","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"oL8Z-1659534012727","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"Aspn-1659534012728","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Cxbz-1659534012729","leaves":[{"text":"6.同时添加两个字段,默认添加到字段最后 alter table +表名 add(字段1 数据类型,\r","marks":[]}]}],"state":{}},{"type":"block","id":"ZoR2-1659534012730","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ugHf-1659534012731","leaves":[{"text":"字段2 数据类型) \r","marks":[]}]}],"state":{}},{"type":"block","id":"SOYv-1659534012732","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"LuqN-1659534012733","leaves":[{"text":"alter table dcs add(age1 int(10),age2 int(10)); ==》同时添加两个字段age1 和age2\r","marks":[]}]}],"state":{}},{"type":"block","id":"Kz0f-1659534012734","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"dVA7-1659534012735","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"fpq0-1659534012736","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"GQV6-1659534012737","leaves":[{"text":"7. 删除表字段 alter table +表名 drop + 字段 \r","marks":[]}]}],"state":{}},{"type":"block","id":"bXG8-1659534012738","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"UAA2-1659534012739","leaves":[{"text":"alter table dcs drop class; ==》删除字段class\r","marks":[]}]}],"state":{}},{"type":"block","id":"eZTv-1659534012740","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"3CNZ-1659534012741","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"GW0m-1659534012742","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"hkRI-1659534012743","leaves":[{"text":"8.删除表两个字段 alter table +表名 drop 字段1,drop 字段2 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Xufw-1659534012744","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"eGw2-1659534012745","leaves":[{"text":"alter table dcs drop age1,drop age2;\r","marks":[]}]}],"state":{}},{"type":"block","id":"mZqh-1659534012746","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"BfZ9-1659534012747","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"VC7s-1659534012748","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vc5u-1659534012749","leaves":[{"text":"9.alter table dcs drop primary key; ==》当前存在自增长,删除主键报错,因为自增长不饿能单独存在\r","marks":[]}]}],"state":{}},{"type":"block","id":"hn8n-1659534012750","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"4aZt-1659534012751","leaves":[{"text":"alter table dcs change id id int(10); ==》删除自增长\r","marks":[]}]}],"state":{}},{"type":"block","id":"XEKw-1659534012752","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"koZs-1659534012753","leaves":[{"text":"alter table dcs drop primary key; ==》删除主键\r","marks":[]}]}],"state":{}},{"type":"block","id":"7xfj-1659534012754","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"DLS7-1659534012755","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"MjJ6-1659534012756","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Ehfs-1659534012757","leaves":[{"text":"10. alter table dcs change id id int(10) primary key auto_increment;\r","marks":[]}]}],"state":{}},{"type":"block","id":"d6bh-1659534012758","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"NEww-1659534012759","leaves":[{"text":"==》不改变id字段添加主键和自增长\r","marks":[]}]}],"state":{}},{"type":"block","id":"Ko1l-1659534012760","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"eJKL-1659534012761","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"zvPa-1659534012762","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0gLG-1659534012763","leaves":[{"text":"9.删除表drop table +表名\r","marks":[]}]}],"state":{}},{"type":"block","id":"Y99-1659534012764","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Q0ow-1659534012765","leaves":[{"text":"drop table dcs1; ==》删除dcs1这个表\r","marks":[]}]}],"state":{}},{"type":"block","id":"J1Qt-1659534012766","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"v0u1-1659534012767","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"zHtD-1659534012768","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vOda-1659534012769","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"igri-1659534012770","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"eXlT-1659534012771","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"MTq2-1659534012772","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vgIm-1659534012773","leaves":[{"text":"10","marks":[]},{"text":"、msyql 数据库的增删改查【重点】","marks":[{"type":"backgroundColor","value":"#FF0001"}]},{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"a8vZ-1659534012774","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"WP2D-1659534012775","leaves":[{"text":"1)增 insert into +dcs表名\r","marks":[]}]}],"state":{}},{"type":"block","id":"M2Xy-1659534012776","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"zh0e-1659534012777","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"OTrP-1659534012778","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"24iA-1659534012779","leaves":[{"text":"单条插入\r","marks":[]}]}],"state":{}},{"type":"block","id":"MuPE-1659534012780","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"iJ2z-1659534012781","leaves":[{"text":"insert into dcs(id,score,name,phone,time)values(1,99.88," xiaoduan',13966668888,'2022-8-3');\r","marks":[]}]}],"state":{}},{"type":"block","id":"4bqg-1659534012783","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"6ii2-1659534012784","leaves":[{"text":"insert="" into="" dcs="" values(2,88.88,'xiaoduan',13933334444,'2022-8-3');\r","marks":[]}]}],"state":{}},{"type":"block","id":"n13y-1659534012785","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"n3tm-1659534012786","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"80wc-1659534012787","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"cdty-1659534012788","leaves":[{"text":"多条插入\r","marks":[]}]}],"state":{}},{"type":"block","id":"csed-1659534012789","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ucyc-1659534012790","leaves":[{"text":"insert="" dcs(id,score,name,phone,time)values(3,66.88,'xiaoduan',13900001111,'2022-8-3'),(4,77.88,'xiaoduan',13023456789,'2022-8-3'),(5,68.99,'xiaoduan',13969696969,'2022-8-3');\r","marks":[]}]}],"state":{}},{"type":"block","id":"lvhu-1659534012791","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"swo8-1659534012792","leaves":[{"text":"insert="" values(6,34.66,'xiaoduan',13523456789,'2022-8-3'),(7,67.00,'xiaoduan',13912341234,'2022-8-3');\r","marks":[]}]}],"state":{}},{"type":"block","id":"le5b-1659534012793","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"jhcw-1659534012794","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"a8yj-1659534012795","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"tik4-1659534012796","leaves":[{"text":"单个字段插入\r","marks":[]}]}],"state":{}},{"type":"block","id":"y3w7-1659534012797","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"rktl-1659534012798","leaves":[{"text":"insert="" dcs(id,name)values(8,'xiaoduan');="=》只给id" name="" 字段插入数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"v010-1659534012799","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"cthe-1659534012800","leaves":[{"text":"insert="" dcs(score,name)values(88.999,'xiaoduan');="=》只给scre" 和name插入数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"ohbm-1659534012801","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"l6ep-1659534012802","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"yu44-1659534012803","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wyf0-1659534012804","leaves":[{"text":"0不等于null,="" 0是一个值,null是一个空属性\r","marks":[]}]}],"state":{}},{"type":"block","id":"5kmu-1659534012805","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"llzi-1659534012806","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"txns-1659534012807","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"w9ss-1659534012808","leaves":[{"text":"2)删除="" delete="" from="" +表名="=》清除全表数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"kTl2-1659534012809","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"GWkR-1659534012810","leaves":[{"text":"delete" where="" id="9" =="》删除id等于9的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"Bo4o-1659534012813","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"GB5t-1659534012814","leaves":[{"text":"delete">6 ==》删除id大于6的数\r","marks":[]}]}],"state":{}},{"type":"block","id":"obBY-1659534012815","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"1wHO-1659534012816","leaves":[{"text":"delete from dcs where !=1; ==》删除id不等于1的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"f5Tj-1659534012817","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"2rs2-1659534012818","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"hJrt-1659534012819","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"IwwS-1659534012820","leaves":[{"text":"truncate dcs ==》快速清除表的全部数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"tYYA-1659534012821","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"JUAm-1659534012822","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"y1bq-1659534012823","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"cBrM-1659534012824","leaves":[{"text":"drop table dcs ==》删除dcs这个表的数据和结构\r","marks":[]}]}],"state":{}},{"type":"block","id":"gXEL-1659534012825","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Weq8-1659534012826","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"K6HV-1659534012827","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"59R5-1659534012828","leaves":[{"text":"注:TRUNCATE,DELETE,DROP放在一起比较: \r","marks":[]}]}],"state":{}},{"type":"block","id":"2XcA-1659534012829","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"aW8k-1659534012830","leaves":[{"text":"TRUNCATE TABLE:快速删除表数据。 \r","marks":[]}]}],"state":{}},{"type":"block","id":"BrQQ-1659534012831","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"4frH-1659534012832","leaves":[{"text":"DELETE TABLE: 按条件删除表数据 \r","marks":[]}]}],"state":{}},{"type":"block","id":"A2yc-1659534012833","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"7CGG-1659534012834","leaves":[{"text":"DROP TABLE:删除表结构和表数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"R14M-1659534012835","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"3ZN7-1659534012836","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"vJtq-1659534012837","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"mLvS-1659534012838","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"od15-1659534012839","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"5MW2-1659534012840","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"t54k-1659534012841","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"cxkh-1659534012842","leaves":[{"text":"3)改 update 表名 set 字段=? where ..\r","marks":[]}]}],"state":{}},{"type":"block","id":"yQjG-1659534012843","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Ar6k-1659534012844","leaves":[{"text":"update dcs set score = 100; ==》把score字段的值全部改为100\r","marks":[]}]}],"state":{}},{"type":"block","id":"NPw9-1659534012845","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"zBjb-1659534012846","leaves":[{"text":"update dcs set name ='xiaoming' where id = 5; ==》把id 等于5的数据name字段值改为xiaoming\r","marks":[]}]}],"state":{}},{"type":"block","id":"KgwI-1659534012847","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"br3e-1659534012848","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"9f8v-1659534012849","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"USDV-1659534012850","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"WhYX-1659534012852","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Q2k0-1659534012853","leaves":[{"text":"4)查\r","marks":[]}]}],"state":{}},{"type":"block","id":"1bCQ-1659534012854","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"nLLe-1659534012855","leaves":[{"text":"1.查询表中所有数据 select * from +表名 ”*“ 代表所有 \r","marks":[]}]}],"state":{}},{"type":"block","id":"jd5g-1659534012856","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"7VEl-1659534012857","leaves":[{"text":"select * from dcs; ==》查询全表数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"KYjB-1659534012858","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"XUmZ-1659534012859","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"e6UG-1659534012860","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0P6u-1659534012861","leaves":[{"text":"2. 查询某个字段的数据 select 字段 from +表名 \r","marks":[]}]}],"state":{}},{"type":"block","id":"7Fa3-1659534012862","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"gImV-1659534012863","leaves":[{"text":"select id from dcs; ==》只查询id字段数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"xv2t-1659534012864","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"31YN-1659534012865","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"V8Dj-1659534012866","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"QZpZ-1659534012867","leaves":[{"text":"3. 查询多个字段的数据 select 字段1,字段2 from +表名 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Uxc2-1659534012868","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"O0H0-1659534012869","leaves":[{"text":"select id,name from dcs; ==》只查询id name 字段的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"QX6I-1659534012870","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"8AEo-1659534012871","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"d4AD-1659534012872","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wA3O-1659534012873","leaves":[{"text":"4.查询满足某个条件的所有数据 select * from +表名 where 字段=值 where 后面接满足的条件 \r","marks":[]}]}],"state":{}},{"type":"block","id":"jOV3-1659534012874","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0IfS-1659534012875","leaves":[{"text":"select * from dcs where id = 1; ==》查询id等于1 的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"JsIB-1659534012876","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"XgeT-1659534012877","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"wnsP-1659534012878","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"iR2i-1659534012879","leaves":[{"text":"5.查询不满足某个条件的所有数据 select * from +表名 where 字段!=value “!=” 代表不等于 \r","marks":[]}]}],"state":{}},{"type":"block","id":"ZXnA-1659534012880","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"JU8R-1659534012881","leaves":[{"text":",也可以用符号 ”<>“ 代表不等于\r","marks":[]}]}],"state":{}},{"type":"block","id":"aBwA-1659534012882","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"MAw4-1659534012883","leaves":[{"text":"select * from dcs where id != 1; ==》查询id不等于1 的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"w2lW-1659534012884","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"MER9-1659534012885","leaves":[{"text":"select * from dcs where id <> 1; ==》查询id不等于1 的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"3LAr-1659534012886","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"lati-1659534012887","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"bm02-1659534012888","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"MPCI-1659534012889","leaves":[{"text":"6.查询同时满足多个条件数据 select * from +表名 where 条件1 and \r","marks":[]}]}],"state":{}},{"type":"block","id":"igLj-1659534012890","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"dobL-1659534012891","leaves":[{"text":"条件2 and 关键字左右的两个条件必须同时满足\r","marks":[]}]}],"state":{}},{"type":"block","id":"sFT5-1659534012892","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"IqFv-1659534012893","leaves":[{"text":"select * from dcs where class = 1833 and sex = 1; ==》查询班级是1833且性别是1的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"yXyy-1659534012894","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"PJ3-1659534012895","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"8d4j-1659534012896","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"mqe8-1659534012897","leaves":[{"text":" \r","marks":[]}]}],"state":{}},{"type":"block","id":"Jfgu-1659534012898","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"kp1n-1659534012899","leaves":[{"text":"7.查询满足至少1个条件的数据 select * from +表名 where 条件1 or 条件2 \r","marks":[]}]}],"state":{}},{"type":"block","id":"OWka-1659534012900","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"pBhY-1659534012901","leaves":[{"text":"or 关键字左右的两个条件至少满足1个,否则返回空 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Qo6u-1659534012902","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"GOaZ-1659534012903","leaves":[{"text":"select * from dcs where class = 1833 or class = 1835; ==》\r","marks":[]}]}],"state":{}},{"type":"block","id":"5dgX-1659534012904","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Jyao-1659534012905","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"SD5L-1659534012906","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"R4so-1659534012907","leaves":[{"text":"8.查询一个条件范围内的数据 select * from +表名 where 字段 between m \r","marks":[]}]}],"state":{}},{"type":"block","id":"c51k-1659534012908","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Wfvp-1659534012909","leaves":[{"text":"and n between...and ... 指定一个范围 \r","marks":[]}]}],"state":{}},{"type":"block","id":"HcKg-1659534012910","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"nNJR-1659534012911","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"34Ps-1659534012912","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Asne-1659534012913","leaves":[{"text":"#查询年龄在25和31 之间的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"o7Y0-1659534012914","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"HmUT-1659534012915","leaves":[{"text":"#select * from student where age between 25 and 31;\r","marks":[]}]}],"state":{}},{"type":"block","id":"Kf1I-1659534012916","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ruwq-1659534012917","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"QO4R-1659534012919","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"UI6i-1659534012920","leaves":[{"text":"9.查询字段满足在指定的集合中的数据 select * from +表名 where 字段 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Van-1659534012921","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"RWie-1659534012922","leaves":[{"text":"in(值1,值2,值3) \r","marks":[]}]}],"state":{}},{"type":"block","id":"orKl-1659534012923","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"3fB9-1659534012924","leaves":[{"text":"#查询class为1833或者class为1835的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"rAnj-1659534012925","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"btiQ-1659534012926","leaves":[{"text":"#select * from student where class in (1833,1835);\r","marks":[]}]}],"state":{}},{"type":"block","id":"Jgtc-1659534012927","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"r4zo-1659534012928","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"y6c4-1659534012929","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"N0b8-1659534012930","leaves":[{"text":"10.查询字段不满足在指定集合中的数据 select * from +表名 where 字段 \r","marks":[]}]}],"state":{}},{"type":"block","id":"Fwnn-1659534012931","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"4lfh-1659534012932","leaves":[{"text":"not in (值1,值2,值3)\r","marks":[]}]}],"state":{}},{"type":"block","id":"DdSx-1659534012933","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Wr6m-1659534012934","leaves":[{"text":"#查询id 不在1和3里面的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"sc7p-1659534012935","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"yd8U-1659534012936","leaves":[{"text":"#select * from student where id not in (1,3);\r","marks":[]}]}],"state":{}},{"type":"block","id":"4458-1659534012937","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"H9GJ-1659534012938","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"qGYk-1659534012939","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"XTKW-1659534012940","leaves":[{"text":"11.#查询年龄大于24和小于31的数据\r","marks":[]}]}],"state":{}},{"type":"block","id":"MrYz-1659534012941","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"5MpK-1659534012942","leaves":[{"text":"#select * from student where age > 24 and age <31;\r","marks":[]}]}],"state":{}},{"type":"block","id":"C5T-1659534012943","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Wl6o-1659534012944","leaves":[{"text":"\r","marks":[]}]}],"state":{}},{"type":"block","id":"YIeS-1659534012945","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"jajW-1659534012946","leaves":[{"text":"","marks":[]}]}],"state":{}}]'>第7讲 mysql数据库
mysql数据库
1、关系型数据库
依据关系模型创建的数据库,把数据保存在不同的表中,表 与表存在着某些关系。
2、非关系型数据库
非关系型数据库也叫nosql数据库,全称not only sql。通常数据以对象的形式存储在数据库中,不固定结构,
例如列模 型,键值对模型。
3、关系型数据库特点
1.安全
2.保持数据的一致性
3.实现对表与表进行复杂的数据查询
4、非关系型数据库特点
1.效率高
2.容易扩展
3.使用更加灵活
5、关系型数据库有哪些
1.db2
2.oracle ==》收费 金融
3.mysql ==》免费
4.sql server ==》微软
6、非关系型数据库有哪些
1.hbase(列模型) ==》大数据
2.redis(键值对模型) ==》缓存
3.mongodb(文档类模型)==》文档类型
7、安装mysql数据库
1)yum install mysql ==》安装mysql数据库客户端
2)yum install mysql-server ==》安装mysql数据库服务端
3)rpm -qa|grep -i mysql ==》查看是否安装了mysql数据库
4)service mysqld status ==》查看MySQL数据库的状态(这个d是daemon 守护的进程)
5)service mysqld start ==》启动MySQL数据
6)service mysqld stop ==》关闭MySQL数据库
7)service mysqld restart ==》重启数据库
8)登录mysql 数据库[root@192 /]# mysql -uroot -p 第一次登录不需要密码
Enter password:
-u 代表用户user意思 root是用户
-p 代表是密码password意思
[root@192 /]mysqladmin -uroot password "123456" ==》修改初始密码123456
9)登录mysql 数据库[root@192 /]# mysql -uroot -p
Enter password: 123456
或者登录mysql 数据库[root@192 /]# mysql -uroot -p123456 ==》直接接密码登录数据库
10)mysql>use mysql; ==》进入到MySQL数据库
11)mysql>show databases; ==》展示所有的数据库 (注意数据库操作sql语句需要接英文分号)
12)mysql>exit; ==》退出MySQL数据库 或者按ctrl+c
13)create database +库名
mysql>create database dcs9; ==》创建一个dcs9这个数据库
14)drop database +库名
mysql>drop database dcs9; ==》删除dcs9这个数据库
15) use dcs9; ==》进入到dcs9这个库
16)select database(); ==》查看当前在哪个库
17)create table +表名(字段1 数据类型 约束,字段2 数据类型 约束,字段3 数据类型 约束...);
mysql>create table dcs(id int(10) primary key auto_increment,score float(10,2)
not null,name varchar(10),phone bigint(10) default 13977778888,time date);
18)show tables; ==》展示当前库下所有的表
19)mysql> desc dcs; ==》查看dcs这个表的表结构(desc ==>description)
+-------+-------------+------+-----+-------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+-------------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| score | float(10,2) | NO | | NULL | |
| name | varchar(10) | YES | | NULL | |
| phone | bigint(10) | YES | | 13977778888 | |
| time | date | YES | | NULL | |
+-------+-------------+------+-----+-------------+----------------+
field ==》字段
type ==》类型
null ==》是否可以为空
key ==》primary key 主键
default ==》默认值
extra ==》额外备注
数据库中常见的数据类型【重点】
数值型
int ==》整型 最大值2147483647
bigint ==》整型 手机号 超过int 就只能用bigint
float ==》浮点型 float(10,2) 整数部分和小数部分加起来是总共10位,2是精确位数,2位小数点
文本型(varchar 和char 存储数据时需要单引号或者双引号)
区别:
1)char 的长度固定的,varchar 是可以变化的
char(10) 和varchar(10)同样存储‘abc’ ,对于char存储三个字节,还有7个回用
空格补上,varchar 存储的只有三个字节,其他7个不会用空格补上
2)char 的效率笔varchar要高
3)varchar 比char节省空间
日期型 存储数据时需要单引号或者双引号
date ==>"2022-8-3"
数据库有哪些约束【重点】
not null ==》非空约束
primary key ==》主键约束 唯一的,不能重复,一个表只有一个主键 如身份证
default ==>默认值约束,不给新值就是用默认
auto_increment ==》自增长约束,不给值时,默认加一,在这个一定要和主键一起使用
foreign key ==》外键约束 表与表之间的约束
8、修改表结构 【重点】
1.查看表结构 desc +表名 显示字段名称,数据类型,约束,备注
desc dcs ==》修改表结构
2.修改表名alter table +表名 rename + 新表名
alter table dcs rename dcs1 ==》把dcs这个表改名为dcs1
3.修改表字段 alter table +表名 change +原字段名 +新字段名 数据类型,约束
alter table dcs change id sid int(10); ==》把id字段改名为sid字段并且取消自增长
alter table dcs change sid id int(10); ==》把sid字段改名位id字段
alter table dcs change id id int(10) auto_increment; ==》不改变id字段加上自增长
4.添加表字段,并放到第一个字段前 alter table +表名 add +字段名 数据类型 约束 first
alter table dcs add class int(10) first; ==》添加一个字段放在最前面
5.添加表字段,并放到某个字段后 alter table +表名 add +字段名 数据类型 约束 after +字段名
alter table dcs add age int(10) after name; ==》添加一个字段放在name字段的后面
6.同时添加两个字段,默认添加到字段最后 alter table +表名 add(字段1 数据类型,
字段2 数据类型)
alter table dcs add(age1 int(10),age2 int(10)); ==》同时添加两个字段age1 和age2
7. 删除表字段 alter table +表名 drop + 字段
alter table dcs drop class; ==》删除字段class
8.删除表两个字段 alter table +表名 drop 字段1,drop 字段2
alter table dcs drop age1,drop age2;
9.alter table dcs drop primary key; ==》当前存在自增长,删除主键报错,因为自增长不饿能单独存在
alter table dcs change id id int(10); ==》删除自增长
alter table dcs drop primary key; ==》删除主键
10. alter table dcs change id id int(10) primary key auto_increment;
==》不改变id字段添加主键和自增长
9.删除表drop table +表名
drop table dcs1; ==》删除dcs1这个表
10、msyql 数据库的增删改查【重点】
1)增 insert into +dcs表名
单条插入
insert into dcs(id,score,name,phone,time)values(1,99.88,'xiaoduan',13966668888,'2022-8-3');
insert into dcs values(2,88.88,'xiaoduan',13933334444,'2022-8-3');
多条插入
insert into dcs(id,score,name,phone,time)values(3,66.88,'xiaoduan',13900001111,'2022-8-3'),(4,77.88,'xiaoduan',13023456789,'2022-8-3'),(5,68.99,'xiaoduan',13969696969,'2022-8-3');
insert into dcs values(6,34.66,'xiaoduan',13523456789,'2022-8-3'),(7,67.00,'xiaoduan',13912341234,'2022-8-3');
单个字段插入
insert into dcs(id,name)values(8,'xiaoduan'); ==》只给id name 字段插入数据
insert into dcs(score,name)values(88.999,'xiaoduan'); ==》只给scre 和name插入数据
0不等于null, 0是一个值,null是一个空属性
2)删除 delete from +表名 ==》清除全表数据
delete from dcs ==》删除dcs表的全部数据
delete from dcs where id = 9 ==》删除id等于9的数据
delete from dcs where id>6 ==》删除id大于6的数
delete from dcs where !=1; ==》删除id不等于1的数据
truncate dcs ==》快速清除表的全部数据
drop table dcs ==》删除dcs这个表的数据和结构
注:TRUNCATE,DELETE,DROP放在一起比较:
TRUNCATE TABLE:快速删除表数据。
DELETE TABLE: 按条件删除表数据
DROP TABLE:删除表结构和表数据
3)改 update 表名 set 字段=? where ..
update dcs set score = 100; ==》把score字段的值全部改为100
update dcs set name ='xiaoming' where id = 5; ==》把id 等于5的数据name字段值改为xiaoming
4)查
1.查询表中所有数据 select * from +表名 ”*“ 代表所有
select * from dcs; ==》查询全表数据
2. 查询某个字段的数据 select 字段 from +表名
select id from dcs; ==》只查询id字段数据
3. 查询多个字段的数据 select 字段1,字段2 from +表名
select id,name from dcs; ==》只查询id name 字段的数据
4.查询满足某个条件的所有数据 select * from +表名 where 字段=值 where 后面接满足的条件
select * from dcs where id = 1; ==》查询id等于1 的数据
5.查询不满足某个条件的所有数据 select * from +表名 where 字段!=value “!=” 代表不等于
,也可以用符号 ”<>“ 代表不等于
select * from dcs where id != 1; ==》查询id不等于1 的数据
select * from dcs where id <> 1; ==》查询id不等于1 的数据
6.查询同时满足多个条件数据 select * from +表名 where 条件1 and
条件2 and 关键字左右的两个条件必须同时满足
select * from dcs where class = 1833 and sex = 1; ==》查询班级是1833且性别是1的数据
7.查询满足至少1个条件的数据 select * from +表名 where 条件1 or 条件2
or 关键字左右的两个条件至少满足1个,否则返回空
select * from dcs where class = 1833 or class = 1835; ==》
8.查询一个条件范围内的数据 select * from +表名 where 字段 between m
and n between...and ... 指定一个范围
#查询年龄在25和31 之间的数据
#select * from student where age between 25 and 31;
9.查询字段满足在指定的集合中的数据 select * from +表名 where 字段
in(值1,值2,值3)
#查询class为1833或者class为1835的数据
#select * from student where class in (1833,1835);
10.查询字段不满足在指定集合中的数据 select * from +表名 where 字段
not in (值1,值2,值3)
#查询id 不在1和3里面的数据
#select * from student where id not in (1,3);
11.#查询年龄大于24和小于31的数据
#select * from student where age > 24 and age <31;
|
|