当前位置:Gxlcms > 数据库问题 > 初时mysql

初时mysql

时间:2021-07-01 10:21:17 帮助过:3人阅读

Create table CeShi1 ( Uid varchar(50) primary key, Pwd varchar(50), Name varchar(50) Nation varchar(50), foreign key (Nation) references Nation(Code) //加外键关系 //references 引用 ) 写查询语句需要注意: 1.创建表的时候,最后一列后面不要写逗号。 2.如果有多条语句一起执行,注意在语句之间加分号分隔。 3.写代码所有符号都是半角的。 关系型数据库:表和表之间是有关系存在的 创建表的几个关键字; 1.主键:primary key 2.非空: not null 3.自增长列:auto_increment 4.外键关系:foreign key (列名) references 表名(列名) CRUD操作: 增删改查 1.添加数据: Insert into 表名 values(‘’,‘’,‘’,‘’)要求values 括号里面的值的个数要求和表里面的列数相同 Insert into Info (Code,Name) values(‘’,‘’) 添加指定列的值 2.修改数据: Update info set Name=’张三’ where Code = ’p001’ 3.删除数据: Delete from info where Code = ‘p001’ 4.查询数据: 1.普通查询:查所有的 Select *from info #查所有数据 Select Code,Name from info #查指定列 2.条件查询 Select *from info where Code =’p001’ #一个条件 Select *from info where Name =’张三’ and Nation =’n001’ #两个条件并的关系 Select *from info where Name =’张三’ or Nation =’n001’ #两个条件或的关系 3.排序查询 Select *from info order by Birthday #默认升序排列asc 若果要降序排列 desc Select *from car order by Brand,Oil desc #多列排序 4.聚合函数 Select count(*) from info #取个数 Select sum(price) from car #查询price列的和 Select avg(price) from car #查询price列的平均值 Select max(price) from car #查询 price列的最大值 Select min(price) from car #查询 price列的最小值 5.分页查询 Select *from car limit n,m #跳过n条数据取m条数据 6.分组查询 Select brand from car group by brand #简单分组查询 Select brand from car group by brand having count(*)>2 #查询系列里面车的数量大于2的系列 7.去重查询 Select distinct brand from car 8.修改列名 Select brand as ‘系列’ from car 9.模糊查询 Select *from car where name like ‘奥迪%’ # %代表任意多个字符 Select *from car where name like ‘_迪%’ # _代表一个字符 10.离散查询 Select *from car where code in (‘c001’,’c002’,’c003’,’c004’) Select *from car where code not in (‘c001’,’c002’,’c003’,’c004’)

 

初时mysql

标签:

人气教程排行