Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a recycle bin for SQL Server 2005\2008


Creating a recycle bin for SQL Server 2005\2008

Author
Message
patr
patr
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 149
hi chris
i appreciate for the good ideas. Unsure
I am also facing the same problem while implementing the triggers and the stored procedures ..please provide the provide the complete script
Misha_SQL
Misha_SQL
SSChasing Mays
SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)

Group: General Forum Members
Points: 620 Visits: 988
Awesome article. I am saving it! Space management is something to watch out for when this approach is implemented (but then again, we all do it anyway, right? :-))



Ronald Beuker
Ronald Beuker
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 43
This is a great idea! I have downloaded and run both SQL scripts. Now when I try to do a DROP TABLE I get this error:

ErrorNumber: 102
ErrorMessage: Incorrect syntax near '-'.


In the Messages box it says:

Caution: Changing any part of an object name could break scripts and stored procedures.

(1 row(s) affected)
The transaction is in an uncommittable state. Rolling back transaction.

The object dbo.[[mytablename]] has been moved to the recycle bin
as object zz_RecycleBin.dbo_$_[[mytablename]]_$_[[my username]]_$_2009_05_27T13_41_14_933


However, the table has not been dropped. And SP_UNDROP says:

There are no objects in the recycle bin

This is on SQL Server 2005 (9.0.4035). What could I do to try solving this?
Duncan RAY-360676
Duncan RAY-360676
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 46
Ronald,

Initially I tried to piece together the code in the article to no avail. I downloaded the sql code shown at the end of the article, made sure that I initiated the "use , ran the code and everything works tickety-boo.

I created the schemas direct in each database where I want to associate this utility.

I have associated the procedure against a number of databases within my SQL SERVER structure, and everything works as documented. As well as the UNDROP code.

When I drop a table, it falls into the recylce schema, and when I UNDROP the table, it reappears as it was before.

Version SQL Server : 9.00.4035.00, SP3, Standard Edition
Chris Goldsmith
Chris Goldsmith
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 151
From the author:

Please see: http://www.sqlservercentral.com/Forums/Topic729503-1553-1.aspx

for my Q&As from the article.
Ronald Beuker
Ronald Beuker
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 43
Hi Chris,

Thanks! Our domain name also has a dash in it. So I have used Chad's bugfix and now it's working great! :-)

Another thought: would it be possible to have all dropped tables, views and so on in a separate database (called 'RecycleBin' for example)?

Best regards,

Ronald
Chris Goldsmith
Chris Goldsmith
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 151
Hi Ronald,

Glad you've found the scripts useful.

Yes, I considered using a separate repository (a database) but one of my goals when designing the solution was to make it as light as possible which is why I went with the schema inside the current database solution.
The separate database solution would also have it's challenges such as permissions on objects, FKs on renamed tables etc.

Chris
dvd_chang
dvd_chang
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 15
Hi, I tried the scripts and it works great. However, the restored table or function name has zz_RecycleBin prefix and postfix with user name and time stamps. Needs to be renamed manually. Anyone else having this problem? or is it designed to be this way to avoid name collision in case a new table or function name being created before doing undrop?
dvd_chang
dvd_chang
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 15
Here is what it looks like in the script

USE [AdventureWorks]
GO
/****** Object: StoredProcedure [zz_RecycleBin].[dbo_$_uspGetManagerEmployees_$_TOSHL35@dad_$_2009_06_07T23_55_38_100] Script Date: 06/08/2009 09:24:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [zz_RecycleBin].[dbo_$_uspGetManagerEmployees_$_TOSHL35@dad_$_2009_06_07T23_55_38_100]
@ManagerID [int]
AS
BEGIN
SET NOCOUNT ON;

-- Use recursive query to list out all Employees required for a particular Manager
WITH [EMP_cte]([EmployeeID], [ManagerID], [FirstName], [LastName], [RecursionLevel]) -- CTE name and columns
AS (
SELECT e.[EmployeeID], e.[ManagerID], c.[FirstName], c.[LastName], 0 -- Get the initial list of Employees for Manager n
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Contact] c
ON e.[ContactID] = c.[ContactID]
WHERE [ManagerID] = @ManagerID
UNION ALL
SELECT e.[EmployeeID], e.[ManagerID], c.[FirstName], c.[LastName], [RecursionLevel] + 1 -- Join recursive member to anchor
FROM [HumanResources].[Employee] e
INNER JOIN [EMP_cte]
ON e.[ManagerID] = [EMP_cte].[EmployeeID]
INNER JOIN [Person].[Contact] c
ON e.[ContactID] = c.[ContactID]
)
-- Join back to Employee to return the manager name
SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[ManagerID], c.[FirstName] AS 'ManagerFirstName', c.[LastName] AS 'ManagerLastName',
[EMP_cte].[EmployeeID], [EMP_cte].[FirstName], [EMP_cte].[LastName] -- Outer select from the CTE
FROM [EMP_cte]
INNER JOIN [HumanResources].[Employee] e
ON [EMP_cte].[ManagerID] = e.[EmployeeID]
INNER JOIN [Person].[Contact] c
ON e.[ContactID] = c.[ContactID]
ORDER BY [RecursionLevel], [ManagerID], [EmployeeID]
OPTION (MAXRECURSION 25)
END;
Fernando Jacinto Alvarez
Fernando Jacinto Alvarez
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 66
could be this useful for recover a dropped column or only for tables and database objects?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search