Wednesday, March 19, 2014

Chapter 9 Suggested Prac. 2... Synonyms!

So here is the code from Chapter 9's second suggested practice.

--First off I check to see if there are any procedures on my system to begin with
SELECT name
FROM sys.procedures
-- Then I create an insert procedure on production.categories like the book suggests
CREATE PROCEDURE Production.CategoriesINSERT
@categoryname nvarchar(15),
@description nvarchar(200)
AS
INSERT INTO production.categories VALUES
(@categoryname, @description)
--I check to see if it works
EXEC production.CategoriesINSERT 'Beer','Budweiser'
--It worked!  Then I create a Synonym for it
CREATE SYNONYM categoryinsert FOR Production.CategoriesINSERT
--Check to see if it worked again
EXEC categoryinsert 'liquor', 'Captain Morgan'
--Now run it without any values and observe the error
EXEC categoryinsert
--The error refers to the procedure, not the synonym because
--the synonym simply points to the procedure


No comments:

Post a Comment