javaweb基础(mysql)

一、mysql基础

                    1)mysql存储结构: 数据库 -> 表 -> 数据   sql语句

                    2)管理数据库:

                                            增加: create database 数据库 defaultcharacter utf8;

                                            删除: drop database 数据库;

                                            修改: alter database 数据库 defaultcharacter gbk;

                                            查询: show databases / show create database 数据库;

                    3) 管理表:      

                                             选择数据库:use 数据库;

                                             增加: create table表(字段名1 字段类型,字段名2 字段类型......);

                                             删除: drop table 表;

                                             修改:          

                                                             添加字段: alter table 表 add [column] 字段名字段类型;               

                                                             删除字段:   alter table 表 drop [column] 字段名;

                                                             修改字段类型: alter table 表 modify 字段名新的字段类型;

                                                             修改字段名称: alter table 表 change 旧字段名 新字段名 字段类型;

                                                    修改表名称:   alter table 表 rename [to] 新表名;

                                            查询:

                                                             showtables  / desc student;

                   4) 管理数据:

                                     增加: insert into 表(字段1,字段2,。。。) values(值1,值2.。。。。);

                                     删除: delete from 表 where 条件;

                                     修改: update 表 set 字段1=值1,字段2=值2...... where 条件;

                                     查询:

                                                      4.1)所有字段: select * from 表;

                                                      4.2)指定字段: select 字段1,字段2.... from 表;

                                                      4.3)指定别名: select 字段1 as 别名 from 表;

                         4.4 )合并列: select (字段1+字段2) from 表;

                                                      4.5)去重: select distinct 字段 from 表;

                                                      4.6)条件查询:

                                                                      a)逻辑条件:and(与)     or(或)

                                                                               select* from 表 where 条件1 and/or 条件2

                                                                 b)比较条件: >  <  >= <=  =  <>  between and(在。。。之间)

                                                                               select* from 表 where servlet>=90;

                                                                      c)判空条件:

                                                                                判断null: is null   /  is not null

                                                                               判断空字符串: =''    /  <>''

                                                                      d)模糊条件: like

                                                                                 %:  替换任意个字符

                                                                                 _:   替换一个字符                   

                                                     4.7分页查询:limit 起始行,查询行数

                                                                      起始行从0开始

                                                     4.8排序: order by 字段 asc/desc

                                                                      asc:正序,顺序

                                                                      desc:反序,倒序

                                                     4.9分组查询:group by 字段

                                                     4.10:分组后筛选: having 条件

                                                    

                                   SQL语句的分类:                 

                                            DDL:数据定义语言

                                                             create/ drop / alter     

                                            DML:数据操作语句

                                                             insert/ delete /update / truncate        

                                            DQL:数据查询语言:

                                               select / show                                            

二、mysql加强

                  1)数据约束(表约束)

                           默认值: default 默认值

                           非空:   not null

                          唯一: unique

                          主键: primary key (非空+唯一)

                          自增长: auto_increment

                          外键: foreign key   约束两种表

                  2)关联查询(多表查询)

                          2.1交叉连接(产生笛卡尔积:原因:连接条件不足够)  表数量-1

                          2.2内连接查询: inner join 

                                            只有满足连接条件的数据才会显示!!!

                          2.3左【外】连接查询:left [outer] join

                                            左表的数据必须全部显示,用左表去匹配右表的数据,如果右表有符号条件的数据则显示符                                          合条件的数据;如果不符合条件,则显示null。

                          2.4右【外】连接查询: right [outer] join

                                            右表的数据必须全部显示,用右表去匹配左表的数据,如果左表有符号条件的数据则显示符                                          合条件的数据;如果不符合条件,则显示null。

                          2.5自连接查询    

                  3)存储过程

                                   --创建存储过程语法

                                   delimeter结束符号

                                   createprocedure 名称(IN/OUT/INOUT  参数名称 参数类型)     

                                   begin

                                            带逻辑的sql语句

                                   end结束符号

 

                                   --调用存储过程

                                   CALL存储过程名称(实际参数);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值