Full Outer Join
Inner Join
Left Join
Right Join
Left Excluding Join
Right Excluding Join
Many to Many Join
CREATE PROCEDURE ProcedureName ( @Parameter1 DataType, @Parameter2 DataType, ⋮ ) AS -- an optional comment ⋮ SQL Commands
CREATE PROCEDURE DoThings ( @NewDepartmentName VARCHAR(50), @NewEmployeeName VARCHAR(50), @NewEmployeeUsername VARCHAR(50) ) AS -- Create a new department INSERT INTO Departments (Department) VALUES (@NewDepartmentName) -- Obtain the ID of the created department DECLARE @NewDepartmentID INT SET @NewDepartmentID = scope_identity() -- Create a new employee INSERT INTO Employees (DepartmentID, Name, Username) VALUES (@NewDepartmentID, @NewEmployeeName, @NewEmployeeUsername) -- Obtain the ID of the created employee DECLARE @NewEmployeeID INT SET @NewEmployeeID = scope_identity() -- List the departments together with their employees SELECT Departments.Department, Employees.Name FROM Departments INNER JOIN Employees ON Departments.DepartmentID = Employees.DepartmentID -- Delete the new employee DELETE FROM Employees WHERE EmployeeID = @NewEmployeeID -- Delete the new department DELETE FROM Departments WHERE DepartmentID = @NewDepartmentID
EXECUTE DoThings 'Research', 'Cristian Darie', 'cristian'
(1 row(s) affected)
(1 row(s) affected)
Department Name
-------------------------------- --------------------------------
Executive Zak Ruvalcaba
Marketing Jessica Ruvalcaba
Engineering Ted Lindsey
Engineering Shane Weebe
Marketing David Levinson
Accounting Geoff Kim
Research Cristian Darie
(7 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)

SELECT * FROM Persons WHERE (P_Id NOT IN(SELECT DISTINCT P_Id FROM orders))
SELECT * FROM Persons LEFT JOIN Orders on Persons.P_Id = Orders.P_Id WHERE Orders.P_Id IS NULL