DML语法:

        insert  注意点:1.在表后可以有括号,表明  所插入的值是哪几列,但是一定要包括所有的not null属性
                                            2.当要为一个表插入的一行数据中有FK,先看FK的值是否存在,
                                               若不存在,则先添加外键所在表中的值,之后再插入
  1. /*
  2. * insert 添加数据
  3. * insert into tableName values('所有数据')
  4. * insert into tableName(部分列名 - 必须包含所有非空列) values('部分列数据')
  5. */
  6. insert into course values('C01', 'JavaSE', 100);
  7. insert into course values('C02', 'JavaSE', '');
  8. insert into course(courseno, coursename) values('C03', 'Oracle');
  9. --insert into course(courseno) values('C04'); -- wrong
  10. -- char固定长度
  11. insert into school values('S8372222', '中国大学');
  12. insert into school values('S8372223', '中国三美大学');
  13. insert into faculty values('01', '计算机系', 'S8372223');
  14. insert into faculty values('02', '土木工程系', 'S8372223');
  15. insert into faculty values('03', '计算机系', 'S8372222');
  16. insert into faculty values('04', '土木工程系', 'S8372222');
  17. insert into major values('M0001', '软件工程', '01');
  18. insert into major values('M0002', '网络工程', '01');
  19. insert into major values('M0003', '建筑', '02');
  20. insert into major values('M0004', '建筑美学', '02');
  21. insert into major values('M0005', '软件工程', '03');
  22. insert into major values('M0006', '网络工程', '03');
  23. insert into major values('M0007', '建筑', '04');
  24. insert into major values('M0008', '建筑美学', '04');
  25. insert into studentcard values('S87232', '中国大学', '张思思', '11级软件04班');
  26. -- insert添加 FK引入PK的值 有值直接使用 无值先insert数据再插入
  27. insert into student values('S0001', '张思思', '', null, null, '无锡', '', 'M0008', 'S87232');
  28. insert into studentcard values('S87233', '中国大学', '张珊珊', '11级软件04班');
  29. insert into student values('S0002', '张珊珊', '女', 20, null, '北京', '68', 'M0005', 'S87233');

update 注意点:update tableName set 列名 = value, ... where ...

  1. update tableName set 列名 = value, ... where ...
  2. -- 部分数据更新 where条件
  3. update student set age = 20;
  4. -- 某一条 PK UK
  5. select * from student; -- PK UK
  6. update student set name = '张三散', sex = '男' where stuNo = 'S9999';
  7. select * from course;
  8. update course set hour = 200 where courseno = 'C05';
  9. 用户登录
  10. update users set password = '123456' where userName = 'admin';
  11. update users set info = 'newInfo' where userName = 'admin';
  12. 中国大学 - 中国社会大学
  13. update school set schoolName = '中国社会大学' where schoolname = '中国大学';
  14. -- 某几条数据 FK
  15. -- 教学部 所有员工 奖金+200
  16. update employee set bonus = bonus + 200
  17. where deptNo = (select deptNo from dept where deptName = '教学部');
  18. -- 软件工程 专业学生 总+10
  19. update student set score = score + 10
  20. where majorno in (select majorNo from major where name = '软件工程');
  21. -- 计算机部 学生总分 + 5
  22. update student set score = score + 5
  23. where unionno = (select unionno from studentunion where unionname = '计算机部');
  24. -- 所有员工工资 + 500
  25. update employee set salary = salary + 500;

    delete    注意点:1.当只想删除一条记录时,where后的条件属性必须是FK  或者  UK
                               2.当一张表中有FK时,有两种方案可以删除(按具体情况使用):
                                                 a. 同时删除(例:删帖子,那么帖子下的回复内容自然同时删除了)
                                                 b.先更新再删除

  1. delete from tableName where ...
  2. -- 删除所有数据
  3. delete from course;
  4. -- 删除某一条数据 PK UK
  5. select * from course;
  6. delete from course where courseno = 'C05';
  7. 某员工辞职
  8. delete from employee where empNo = 'empNo';
  9. select * from student;
  10. delete from student where stuNo = 'S9008';
  11. 某商品下架
  12. -- 中国大学 计算机系 撤销
  13. -- 删除数据 数据FK被引用
  14. --学生
  15. update student set majorno = 'M0007'
  16. where majorno in (select majorno from major
  17. where facultyno =(select facultyno from faculty
  18. where fname = '计算机系' and schoolcode
  19. = (select schoolcode from school
  20. where schoolname = '中国大学')));
  21. --专业
  22. delete from major where facultyno = (select facultyno from faculty
  23. where fname = '计算机系' and schoolcode
  24. = (select schoolcode from school
  25. where schoolname = '中国大学'));
  26. --院系
  27. delete from faculty where fname = '计算机系'
  28. and schoolcode = (select schoolcode from school
  29. where schoolname = '中国大学');
  30. -- 同时删除
  31. 课程C01 JavaSE 100 开设有问题
  32. delete from studentcourse where courseno = 'C01';
  33. delete from course where courseno = 'C01';
  34. BBS论坛
  35. 帖子 - 回复 帖子内容有严重问题
  36. delete from reply where postId = '0001';
  37. delete from post where postId = '0001';
  38. -- 更新 再删除
  39. -- 大学毕业 学生证失效
  40. update student set cardno = null;
  41. delete from studentcard;


























最新文章

  1. bug注意事项记录
  2. 腾讯云>>云通信>>TLS后台API在mac上JAVA DEMO搭建
  3. gcc 和g++区别
  4. Python OpenCV —— Arithmetic
  5. 从题目中学习java语法
  6. Bootstrap--全局css样式之表单
  7. OpenStack G版以后的Availability Zone与Aggregate Hosts
  8. django-celery提供给顾客使用实例
  9. 大数据学习系列之二 ----- HBase环境搭建(单机)
  10. eclipse使用javaFX写一个HelloWorkld
  11. maven生成项目慢解决办法
  12. python 模块 wmi 远程连接 windows 获取配置信息
  13. 49.字符串转int
  14. byte & 0xff char 转换
  15. Android-TabLayout设置内容宽度以及下划线宽度
  16. 自定义Team Foundation Server (TFS) 与Project Professional的集成字段
  17. 编程开发之--java多线程学习总结(1)问题引入与概念叙述
  18. openstack架构设计(一)
  19. 使用location.hash保存页面状态
  20. Appium+python自动化29-toast消息(亲测 ok)

热门文章

  1. mydumper原理4
  2. Jquery Validate根据其他元素的事件来触发单个元素的异步校验
  3. qt 获取系统磁盘空间大小
  4. OpenVPN中的几个和连接相关的Timer解析
  5. php 正则中文匹配
  6. TCP/IP协议原理与应用笔记17:IP编址(重点)
  7. 使用 collectionView 实现表头,区头,区尾
  8. Java 8: Lambdas和新的集合Stream API
  9. Linux下VirtualBox出现kernel driver not installed的解决方法
  10. CentOS7.0 重置Root的密码