if object_id('Configuration') IS NOT NULL drop table Configuration GO Create Table Configuration ( tablename varchar(25), value int ) GO insert into Configuration select 'OrderRecord', 0 insert into Configuration select 'Contact', 10000 GO if object_id('OrderRecord') IS NOT NULL drop table OrderRecord GO Create Table OrderRecord ( OrderRecordID int PRIMARY KEY CLUSTERED, ContactID int, ItemName varchar(255), ItemCount int, Cost money ) GO if object_id('Contact') IS NOT NULL drop table Contact GO Create Table Contact ( ContactID int PRIMARY KEY CLUSTERED, FirstName varchar(255), LastName varchar(255) ) GO if object_id('UpdateConfiguration') IS NOT NULL drop procedure UpdateConfiguration GO Create Procedure UpdateConfiguration (@ID int = NULL OUTPUT, @tablename varchar(25)) AS BEGIN TRAN Declare @CurrentValue int Select @CurrentValue = value From Configuration Where tablename = @tablename Set @ID = @CurrentValue + 1 Update Configuration Set value = @ID Where tablename = @tablename COMMIT TRAN GO if object_id('AddContact') IS NOT NULL drop procedure AddContact GO Create Procedure AddContact ( @ContactID int = NULL OUTPUT, @FirstName varchar(255), @LastName varchar(255) ) As exec UpdateConfiguration @ContactID OUTPUT, 'Contact' Insert Into Contact Values (@ContactID, @FirstName, @LastName) GO if object_id('AddOrderRecord') IS NOT NULL drop procedure AddOrderRecord GO Create Procedure AddOrderRecord ( @OrderRecordID int = NULL OUTPUT, @ContactID int, @ItemName varchar(255), @ItemCount int, @Cost money ) As Declare @ID int exec UpdateConfiguration @ID OUTPUT, 'OrderRecord' Insert Into OrderRecord Values (@ID, @ContactID, @ItemName, @ItemCount, @Cost) GO Select * From Configuration Select * From Contact Select * From OrderRecord Declare @ContactID int, @OrderRecordID int exec AddContact @ContactID OUTPUT, 'Tim', 'Spoon' exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Hot Dog', 1, 9 exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Mustard', 1, .25 exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Chili', 2, .50 exec AddContact @ContactID OUTPUT, 'Suzy', 'Fork' exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Dell Computer', 1, 2000 exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Fuzzy Mouse', 1, 19 exec AddContact @ContactID OUTPUT, 'Peter', 'Knife' exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Racy Suspenders', 1, 11 exec AddContact @ContactID OUTPUT, 'Darla', 'Cutlery' exec AddOrderRecord @OrderRecordID OUTPUT, @ContactID, 'Shag Carpet', 1, 13 Select * From Configuration Select * From Contact Select * From OrderRecord