C/S: Client Server

B/S: Brower Server

Php主要实现B/S

.net IIS

Jave TomCat

LAMP:L

Mysql:常用代码

Create table ceshi1

(

Uid varchar(50) primary key,

Pwd varchar(50),

Name varchar(50),

Nation varchar(50),

foreign key(nation) references nation(code)

)

写查询语句需要注意:

  1. 创建表的时候,最后一列不要写逗号
  2. 如果有多条语句一起执行,在语句之间加分号
  3. 写代码所有符号都是半角的

关系型数据库:表和表之间是有关系存在的

创建表时的几个关键字

  1. 主键:primary key
  2. 非空:not null
  3. 自增长列:auto_increnment 例:Pwd varchar(50) auto_increnment-----mysql里专用
  4. 外键关系:foreign key(列名) references 表名(列名)-----mysql里专用

CRUD操作:

  1. 添加数据:

Insert into info values(‘’,’’,’’) 要求values 括号里的值个数要和表里列数相同

Insert into info (code,name) values(‘’,’’) 添加指定列

  1. 修改数据

Update info set name =’张三’ where code =’p001’

  1. 删除数据

Delete from info where code =’p001’

  1. 查询数据:

普通查询:

Select * from info 查所有的

Select code,name from info 查指定列

条件查询:

Select * from info where code =’p001’

Select * from info where name=’张三’ and nation =’n001’

Select * from info where name=’张三’ or nation =’n001’

排序查询:

Select * from info order by birthday #默认升序asc  降序desc

Select * from car order by brand,oil desc #多列排序

 

聚合函数:

Select count(*) from info #取个数 可以写*也可以写主键列 一般写主键列(占内存少)

Select sum(price) from car

Select avg(price) from car

Select max(price) from car

Select min(price) from car

分页查询:

Select * from car limit 0,5 #跳过n条数据,取m条数据

分组查询:

Select brand from car group by brand #简单分组查询

Select brand from car group by brand having count (*)>2 #查询系列里面车的数量大于2的系列

去重查询:

Select distinct brand from car

修改列名:

Select brand as ’系列’ from car

模糊查询:

Select * from car where name like ‘_迪%’  %代表任意多个字符 _代表一个字符

离散查询:

Select * from car where code in (‘c001’,’c002’,’c003’)

Select * from car where code not in (‘c001’,’c002’,’c003’)

高级查询:

  1. 连接查询

Select * from info,nation #得出的结果称为笛卡尔积

Select * from info,nation where info.nation=nation.code

Join on

Select * from info join nation #join 连接

Select * from info join nation on info.nation=nation.code

  1. 联合查询

Select code,name from info

Union

Select code,name from nation

  1. 子查询

1)  无关子查询

Select code from nation where name=’汉族’ #取nation表中查询汉族的民族代号

Select * from info where nation=()#在info表中查询民族代号为上一个查询结果的所有信息

Select * from info where nation=(Select code from nation where name=’汉族’)

子查询的结果被父查询使用,子查询可以单独执行的称为无关子查询

2)  相关子查询

Select * from car where oil<(该系列的平均油耗)

Select avg(oil)from car where brang=’值’ #查询某系列的平均油耗

Select * from car a where oil<( Select avg(oil) from car b where b.brang=’a.brand’)

Mysql:常用代码的更多相关文章

  1. Php mysql 常用代码、CURD操作以及简单查询

    C/S:Client ServerB/S:Brower Server php主要实现B/S LAMP :Linux系统    A阿帕奇服务器    Mysql数据库   Php语言 mysql常用代码 ...

  2. MySQL常用代码

    create database 数据库名 create table CeShi1( Uid varchar(50) primary key, Pwd varchar(50), Name varchar ...

  3. Mysql基础代码(不断完善中)

    Mysql基础代码,不断完善中~ /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限 ...

  4. MySQL数据库3 - MySQL常用数据类型

    一. MySql常用数据类型 数据类型:整数(tinyint smailint int bigint) 定点数 decimal(p,s) ------ 小数点位置固定的       ---> 数 ...

  5. mysql常用函数参考

    mysql常用函数参考   对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str) 返回字符串str的最左面字符的ASCII代码值.如果str是空字符串,返回0.如果str是NULL, ...

  6. PHP常用代码大全(新手入门必备)

    PHP常用代码大全(新手入门必备),都是一些开发中常用的基础.需要的朋友可以参考下.   1.连接MYSQL数据库代码 <?php $connec=mysql_connect("loc ...

  7. 学生选课数据库SQL语句45道练习题整理及mysql常用函数(20161019)

    学生选课数据库SQL语句45道练习题: 一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四 ...

  8. MySQL常用的七种表类型(转)

    MySQL常用的七种表类型(转)   其实MySQL提供的表类型截至到今天已经有13种,各有各的好处,但是民间流传的常用的应该是7种,如果再细化出来,基本上就只有两种:InnoDB.MyIASM两种. ...

  9. phpcms v9模板制作常用代码集合(转)

    phpcms v9模板制作常用代码集合(个人收藏) 1.截取调用标题长度 {str_cut($r[title],36,'')} 2.格式化时间 调用格式化时间 2011-05-06 11:22:33 ...

随机推荐

  1. java 格式化日期(DateFormat)

    import java.text.DateFormat; import java.util.Date; /** * 格式化时间类 DateFormat.FULL = 0 * DateFormat.DE ...

  2. SQL Server 2008 远程过程调用失败

    今天在写程序的时候,突然间发现数据库连接不上了,打开管理器发现SQL2008出现这样的错误. 非常的郁闷,找了好多方法都没有解决,最后想想是不是应为安装vs2013中的SQL Server Expre ...

  3. 顺序容器:vector,deque,list

    1.顺序容器:vector,deque,list 容器类共享公共接口,只要学会其中一种类型就能运用另一种类型.每种容器提供一组不同的时间和功能这种方案,通常不需要修改代码,秩序改变类型声明,每一种容器 ...

  4. FindWindow()&&FindWindowEx

    这个函数呢,我一般用来自动刷刷网页啥的比如我最近就在刷52破解的在线时间,好啦怎么用是你自己的事情. FindWindow()主要用来获取目标句柄 或着说窗口的权限 HWND FindWindow( ...

  5. sql2008还原问题

    2003的服务器系统不知是因为对SSD的支持不好还是别的原因,系统使用有很多奇怪的问题,所以就升级一下系统,在备份数据库的时候出现了各种问题 源数据库与现数据库都为sqlserver2008,并都安装 ...

  6. 3243: [Noi2013]向量内积 - BZOJ

    Description 两个d 维向量A=[a1,a2,...,ad]与B=[b1,b2,...,bd]的内积为其相对应维度的权值的乘积和,即: 现有 n 个d 维向量x1,...,xn ,小喵喵想知 ...

  7. 学习Ember遇到的一些问题

    1.在模板中不能省略结束标签: 在Ember的模板中,如果省略结束标签的话,会有好多无解的问题(可能是:不更新.更新后结构不对.model和view不同步等),苦苦找了很久.... 2.childVi ...

  8. 【POJ】【1741】/【BZOJ】【1468】Tree

    点分治 怎么又一道叫Tree的题目……真是醉了. 本题为漆子超论文<分治算法在树的路径问题中的应用>例一 题解 : http://blog.csdn.net/sdj222555/artic ...

  9. javamail邮件发送报错解决方案

    如果你用myEclipse进行开发的话,运行时可能会出现以下的错误:Exception in thread "main" java.lang.NoClassDefFoundErro ...

  10. DX SetFVF

    自由顶点格式(flexible vertex format,FVF) http://www.cnblogs.com/xmzyl/articles/1604096.html if( SUCCEEDED( ...