一、视图作业
1、CREATE VIEW v_emp_dept_id__1
AS
SELECT emp_name,address FROM emp;
2、CREATE VIEW v_emp_dept
AS
SELECT emp_name,address,dept_name FROM emp e,dept d
WHERE e.dept_id=d.dept_id
AND dept_name='销售部';
3、CREATE VIEW v_dept_emp_count(dept_name,emp_count,avg_salay)
AS
SELECT COUNT(emp_id),AVG(salary),dept_name FROM emp e,dept d
WHERE e.dept_id=d.dept_id
GROUP BY dept_name;
4、ALTER VIEW v_emp_dept
AS
SELECT emp_name,address,salary,dept_name FROM emp e,dept d
WHERE e.dept_id=d.dept_id
5、SHOW FULL TABLES;
DESC v_emp_dept_id__1;
DESC v_emp_dept;
DESC v_dept_emp_count;
SHOW CREATE VIEW v_emp_dept_id__1;
SHOW CREATE VIEW v_emp_dept;
SHOW CREATE VIEW v_dept_emp_count;
6、DROP VIEW v_emp_dept_id__1,v_emp_dept,v_dept_emp_count;
二、存储过程作业
1、DELIMITER $$
CREATE
PROCEDURE `nmx`.`s1`()
BEGIN
SELECT SUM(salary) FROM emp;
END$$
DELIMITER ;
2、call s1();
3、DELIMITER $$
CREATE
PROCEDURE `nmx`.`s2`(IN e_name CHAR(20))
BEGIN
SELECT address FROM emp WHERE emp_name=e_name;
END$$
DELIMITER ;
4、CALL s2('刘云飞');
5、DELIMITER $$
CREATE
PROCEDURE `nmx`.`avg_sai`(IN d INT,IN g CHAR(2),OUT out_salary INT )
BEGIN
SELECT AVG(salary) INTO out_salary FROM emp WHERE dept_id=d AND gender=g;
END$$
DELIMITER ;
6、CALL avg_sai(1,'男',@out_salary);
SELECT @out_salary;
7、DROP PROCEDURE `nmx`.`s1`;
DROP PROCEDURE `nmx`.`s2`;
DROP PROCEDURE `nmx`.`avg_sai`;