/* Learn basic grammar of things */
/* Add a unique index to the classroom name */
ALTER table class Add constraint uni_classname unique (name)
/* Create stored procedures, which add teachers, and add classrooms */
CREATE proc Pro_addclass
@className varchar (50),
@teacherName varchar (50)
As
Begin
DECLARE @teacherid int
Select @teacherid =id from teacher a where [email protected]
BEGIN Tran
IF (@teacherid =0 or @teacherid is null)
Begin
Insert into teacher (name) VALUES (@teachername)
Select @teacherid =ident_current (' teacher ')
End
INSERT into Class (Teacherid,name) VALUES (@teacherid, @classname)
IF @ @error <>0
Begin
Rollback Tran
End
Else
Commit Tran
End
/* Execute stored procedure, view results */
exec pro_addclass ' Soft ', ' Teacher Li '
exec pro_addclass ' Math ', ' Teacher Ann '
The main is to record their own learning process, these basic knowledge of the park has been a lot of sharing, reference to your information, and then as a record of self-study, if there is a mistake, please correct me
SQL Series learning stored procedures & Things syntax