CREATE PROCEDURE dbo.dbshrink
AS
DECLARE @dataf NVARCHAR(50);
DECLARE @lf NVARCHAR(50);
DECLARE @df NVARCHAR(50);
SELECT @dataf = name FROM SYS.database_files df WHERE df.type_desc = 'rows';
SELECT @lf = name FROM SYS.database_files df WHERE df.type_desc = 'log';
SET @df = DB_NAME();
DECLARE @q NVARCHAR(300);
SET @q = ('ALTER DATABASE ' + @df + ' SET RECOVERY SIMPLE; DBCC SHRINKFILE (' + @lf + ', 1); DBCC SHRINKFILE ('+@dataf+', 0); ALTER DATABASE ' + @df + ' SET RECOVERY FULL;');
TRUNCATE TABLE wx_systemLog;
TRUNCATE TABLE ws_UserAccountView;
EXECUTE sp_executesql @q
GO