慕丝2536941
create proc Addemp @deptno varchar(20) , --// 传入部门代号 @empno varchar(20) , @ename varchar(50) , @job varchar(20) = null , @mgr varchar(100) = null , @hiredate datetime = null , @sal float = null , @comm varchar(20) = null as--------------//begin tran ------// 判断部门是否存在 , 如不存在先添加部门 if(not exists(select deptno from dept where deptno = @deptno)) begin insert into dept ( deptno ) select @deptno if(@@error<> 0 ) begin rollback tran return end --------------------// 添加员工信息 insert into emp (empno , ename , job , mgr , hiredate , sal , comm , deptno) select @empno , @ename ,@ job , @mgr , @hiredate , @sal , @comm , @deptno begin rollback tran return end end commit tran