liangzhiwen

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
函数:
字符串
日期时间
数学

子查询:嵌套查询
1. 做子查询: select sclass from studb where sname=‘..’
2.select * from studb where sclass = (select sclass from studb where sname=‘..’)

sales 

select * from employee where deptno = (select deptno from dept where dname=‘sales’)

连接查询:
内连接: 
select ename,dname,loc from employee e ,dept d where e.deptno=d.deptno

select ename,dname,loc from employee e inner join dept d on e.deptno=d.deptno

外链接: 主表  从表

select ename,… from employee e left outer join dept d on e.deptno=d.deptno

select ename,… from employee e right outer join dept d on e.deptno=d.deptno

full join …on  (oracle,sql server) 

  左连接  union   右连接
自连接
 

视图: view  

create view 视图名 as 查询语句

create or replace view 视图名  as 查询语句

drop view 视图名


事务:
保证业务逻辑(功能:转账)

begin; 开启事务

rollback  回滚

commit  提交

pycharam 与mysql 数据库的交互

pycharm (编码)——》mysql服务器

import pymysql
conn = pymysql.connect(host=“ip|(localhost|127.0.0.1)”,port=3306,db=“数据库”,user=“root”,password=“123456”,charset=“utf8”)

Connection对象
方法:
cursor() 
commit()
close()

Cursor对象:
方法:
execute(sql,params)  —> 返回受影响的行数
fetchOne()  —>元组  结合下标获取具体
fetchall() ——>((),(),(),())  元组   ——》遍历 : 得到内层的元组
scroll(int) —> 正: 下   ,负:上
cursor.close() —>释放资源


xxx管理系统 ——》dbhelper.py

 

posted on 2018-09-12 09:40  liangzhiwen  阅读(161)  评论(0编辑  收藏  举报