1 / 7

第 8 单元 数据库 (II)

第 8 单元 数据库 (II). 目标内容: 第 25 章 数据库的增加 / 删除操作 第 26 章 表达式与相关函数 第 27 章 数据库的查询操作 第 28 章 数据的导入与导出. 第 25 章 数据库的增加 / 删除操作. 25.1 Insert 插入数据 1. INSERT INTO [LOW_PRIORITY|DELAYED] Tablename ( 字段 1 ,字段 2,...) values(exp1,exp2,...);

inari
Download Presentation

第 8 单元 数据库 (II)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第8单元 数据库(II) 目标内容: • 第25章 数据库的增加/删除操作 • 第26章 表达式与相关函数 • 第27章 数据库的查询操作 • 第28章 数据的导入与导出

  2. 第25章 数据库的增加/删除操作 • 25.1 Insert 插入数据 • 1. INSERT INTO [LOW_PRIORITY|DELAYED] Tablename (字段1,字段2,...) values(exp1,exp2,...); • eg: insert into xjb (id,xm,xb,csny,cj) values(1,“张三”,1989-9,401);学号(id)姓名(xm)性别(xb)出生年月(csny)综合成绩(cj) • 张三男1988-94012. • REPLACE [LOW_PRIORITY|DELAYED] Tablename (字段1,字段2,...) values(exp1,exp2,...); • 类似insert,但前者对唯一性字段忽略,后者强制替换。 • 25.2 UPDATE更新数据 • UPDATE [LOW_PRIORITY] Tablename SET(字段1=exp1,字段2=exp2,...[WHERE EXPR]); • 25.3 DELETE 删除数据 • DELETE [LOW_PRIORITY] FROM Tablename [WHERE EXPR] [LIMIT #]; • delete from xjb where xm='李四' limit 1;

  3. 第26章 表达式与相关函数除操作 • 26.1算术运算符及常用数学函数 • 1.运算符P284:+ - * / ,abs(x),sign(x),mod(n,m),round(x) ,log(x),exp(x), • 2.使用select或where子句作运算: • eg: mysql> select abs(-1); mysql> select mod(10,3); • 26.2比较运算符 • P286比较运算符: =,!=,<>,<,>,>=,<=,<=>, IS NULL • eg: select * from xjb where cj>400; • 26.3逻辑运算符 • 1. and(&&),or(||),not(!) • eg: select * from xjb where xb='男' and cj>400; • 2. Like, %通配符,_或?, • 26.4字符串函数 • 1.AscII(x) 返回X的AscII码值 • 2.Locate(s1,s2) 返回s1在s2中第一个出现的位置。 • 3.P290 表eg: select * from xjb where substring(phone_no,1,1)='8';

  4. 第27章 数据库的查询操作 27.1 select语法 select column1,column2,...from table1,table2,...where conditions; eg: select * from costomers; select * from costomers limit 3; select first_name,Last_name from costomers where dob=“jan”;//找出 一月出生的客户 select max(customer_ID) as num from costomers; 27.2 select语法进阶 1.order by 字段[num][desc递减/asc递增/distinct去掉重复] eg:select * from costomers order by address;按地址排序 select * from costomers order by 2;按指定选择后的第二个字段排序 select * from costomers order by id desc;按id递减 2.groub by 按字段分组, 常用于统计 3.Having 与where 类似,差别见P297

  5. 第28章 数据的导入与导出 28.1 数据导入的方法 1.XML语句 2.bulk copy Protocol(BCP) 3.导出成文本文件 4.转换程序 如Access 28.2 MySQL数据导入方法 1.批量导入 把命令放在sql文件中 eg: mysql <new_data.sql; selec * from customers; 2.Mysqlimport文件 在mysql\bin下 mysqlimport (opt1,opt2...) 数据库名 文本文件件名 3.数据嵌入 eg: Load data infile "路径/costomer.txt" into table coustomers; 28.3数据导出 1.MySQL导出工具Mysqldump mysqldump (opt1,opt2...) 数据库名 [table] > 文本文件件名 其他参数:P306 2.select outfile导出数据 eg: select * into outfile "完整路径/result.txt";

  6. 使用phpMyAdmin工具管理MySQL数 据库 1.下载工具图形化的管理软件phpAdmin: http://www.phpmyadmin.net/ 1)解压后的文件夹phpmyadmin,拷贝到服务器根目录下, 2)设置config.inc.php,帐号,密码等 3)本地服务器数据库登录:(或使用集成环境中的管理MYSQL菜单) http://127.0.0.1/phpmyadmin/index.php管理员 帐号:root 密码:空 2.校园服务器数据库登录工具phpAdmin: http://mail.qxntc.edu.cn/~tumingyou/sql/ 个人帐号:tumingyou **** 密码:**** 3.PHPmyadmin创建数据库演示:

  7. 实践与操作: 1.使用phpMyadmin导入zcb.sql文件建立注册模块表zcb 2.完成设计注册登录模块, 1)注册信息存于数据库表zcb中, 2)登录模块取数据比较符合则通过进入指定页面!

More Related