Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

Creating a recycle bin for SQL Server 2005\2008 Expand / Collapse
Author
Message
Posted Thursday, May 21, 2009 10:31 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, June 8, 2009 4:43 AM
Points: 60, Visits: 149
hi chris
i appreciate for the good ideas.
I am also facing the same problem while implementing the triggers and the stored procedures ..please provide the provide the complete script
Post #721828
Posted Saturday, May 23, 2009 12:46 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, July 21, 2014 8:42 AM
Points: 535, Visits: 750
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? )


Post #722619
Posted Wednesday, May 27, 2009 5:49 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, March 10, 2014 4:46 AM
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?

Post #723980
Posted Wednesday, May 27, 2009 8:35 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 6:23 AM
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

Post #724175
Posted Friday, June 5, 2009 4:38 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2014 5:23 AM
Points: 6, Visits: 144
From the author:

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

for my Q&As from the article.
Post #729546
Posted Monday, June 8, 2009 2:04 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, March 10, 2014 4:46 AM
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
Post #730521
Posted Monday, June 8, 2009 6:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2014 5:23 AM
Points: 6, Visits: 144
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
Post #730640
Posted Monday, June 8, 2009 10:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 24, 2009 11:18 AM
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?
Post #730775
Posted Monday, June 8, 2009 10:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 24, 2009 11:18 AM
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;
Post #730798
Posted Friday, June 12, 2009 4:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 10, 2014 7:10 PM
Points: 3, Visits: 45
could be this useful for recover a dropped column or only for tables and database objects?
Post #734171
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse