Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure executing several commands 4

Status
Not open for further replies.

emmy

MIS
Nov 7, 2000
22
US
I've create a series of short commands that make some modifications to some tables. I figured since they must happen sequentially that I would create a stored procedure that runs all of them. It works fine, but I worry that as the database grows and each command takes more time, that the commands will overlap each other and fail. Here is the code - (please forgive the different styles, I fully admit to blatant plagiarisms when coding).

Code:
CREATE PROCEDURE Deactivate_Accounts
@PathFileName varchar(100)
AS

--Clear old values from table
TRUNCATE TABLE Inactive_Employees
--Populate Table
DECLARE @SQL varchar(2000)

-- Valid format: Jsmith,John,Smith,Franklin
  SET @SQL = "BULK INSERT Inactive_Employees FROM '"+@PathFileName+"' WITH (FIELDTERMINATOR = ',') "

EXEC (@SQL)

--Add GUID to Inactive_Employees table
UPDATE Inactive_Employees
	SET tpGUID = tps_guid
FROM Inactive_Employees
	Inner Join tps_user
	ON Inactive_Employees.stUserID = tps_user.tps_title

--Delete inactive employees from user_group table
DELETE tps_user_group
FROM tps_user_group
INNER JOIN Inactive_Employees ON Inactive_Employees.tpGUID = tps_user_group.tps_user_id

--Mark inactive employees as deleted
UPDATE tps_user
SET tps_deleted = '1'
WHERE 
	tps_title IN (SELECT stUserID FROM Inactive_Employees)
AND
	tps_deleted <> '1'

Can I improve this so my commands won't overlap? Any other comments are also welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top