In this example we do so to 500MB (this was for testing instances on local pc)
sp_configure 'show advanced options',1 go reconfigure go sp_configure 'max server memory', 500 go reconfigure go
sp_configure 'show advanced options',1 go reconfigure go sp_configure 'max server memory', 500 go reconfigure go
CREATE FUNCTION [dbo].[fn_SqueezeSpaces] (@String varchar(8000)) RETURNS VARCHAR(8000) AS BEGIN RETURN REPLACE(REPLACE(REPLACE(@String,' ',''),' ',''),' ','') END
-- disable an index ALTER INDEX IX_Contact_EmailAddress ON Person.Contact DISABLE
-- re-enable the index (by rebuilding) ALTER INDEX IX_Contact_EmailAddress ON Person.Contact REBUILD
-- see what indexes are disabled SELECT [NAME], [TYPE_DESC], [IS_DISABLED] FROM SYS.INDEXES WHERE [IS_DISABLED] = 1
DECLARE KILLUSERPROCESS CURSOR FORWARD_ONLY FOR SELECT SPID FROM SYSPROCESSES WHERE LTRIM(RTRIM(LOGINAME)) = 'login' DECLARE @intSPID INT DECLARE @chvDSQL VARCHAR(128) OPEN KILLUSERPROCESS FETCH NEXT FROM KILLUSERPROCESS INTO @intSPID WHILE (@@FETCH_STATUS = 0) BEGIN IF EXISTS (SELECT SPID FROM SYSPROCESSES WHERE LTRIM(RTRIM(LOGINAME)) = 'login' AND SPID = @intSPID) BEGIN SET @chvDSQL = 'KILL ' + CAST(@intSPID AS VARCHAR) EXEC( @chvDSQL) END FETCH NEXT FROM KILLUSERPROCESS INTO @intSPID END CLOSE KILLUSERPROCESS DEALLOCATE KILLUSERPROCESS
CREATE TRIGGER [schemaname].[TRG_triggername] ON [schemaname].[tablename] FOR DELETE,INSERT,UPDATE AS DECLARE @ACTION CHAR(6) DECLARE @DELETE BIT DECLARE @INSERT BIT SET @DELETE = 0 SET @INSERT = 0 IF EXISTS (SELECT TOP 1 1 FROM DELETED) SET @DELETE = 1 IF EXISTS (SELECT TOP 1 1 FROM INSERTED) SET @INSERT = 1 IF @INSERT = 1 AND @DELETE = 1 SET @ACTION = 'UPDATE' IF @INSERT = 1 AND @DELETE = 0 SET @ACTION = 'INSERT' IF @DELETE = 1 AND @INSERT = 0 SET @ACTION = 'DELETE' IF @INSERT = 0 AND @DELETE = 0 RETURN /* Do Stuff here. Refer to Added and Updated records from the INSERTED table select * from inserted Refer to Removed records from the DELETED table select * from deleted e.g. INSERT INTO AuditTable 'INSERT', GETDATE(), * FROM INSERTED */ GO
/* version 2 : 1) displays progress of search in the messages window, 2) takes search term as a parameter 3) provides sql at the end to examine the located data */ declare @columncount int declare @searchdata varchar(255) -- set string to search for here set @searchdata = 'Utility%Connections' select @columncount = count(*) from information_schema.columns where data_type in ('ntext','smallint','int','char', 'varchar', 'nvchar', 'nvarchar') and table_schema = 'dbo' and table_name not like 'sync%' and column_name <> 'order' select 'declare @resultslist varchar(max)' + char(10) + 'set @resultslist = ''''' union select 'if exists (select 1 from [' + table_name + '] where [' + column_name + '] like ''%' + @searchdata + '%'' ) ' + char(10) + ' begin ' + char(10) + ' set @resultslist = @resultslist + char(10) + ''select [' + column_name + '],* from ['+ table_name + '] where [' + column_name + '] like ''''%' + @searchdata + '%'''''''+ char(10) + ' print ''' + table_name + '/' +column_name + '''' + char(10) + ' end ' + char(10) + '' + char(10) + ' print ''' + cast(cast(cast(rank() OVER (ORDER BY table_name, column_name) as float)/ @columncount *100 as decimal(10,2)) as varchar(10))+ '%' + '''' + char(10) from information_schema.columns where data_type in ('ntext','smallint','int','char', 'varchar', 'nvchar', 'nvarchar') and table_schema = 'dbo' and table_name not like 'sync%' and column_name <> 'order' union select 'print @resultslist' + char(10) + 'go'
EXEC sp_configure 'show advanced option', '1' RECONFIGURE; GO EXEC sp_configure 'xp_cmdshell', 1 GO RECONFIGURE; -- remember to turn advanced options off again! EXEC sp_configure 'show advanced option', '0' RECONFIGURE GO
EXEC SP_CONFIGURE 'show advanced options' , '1'; GO RECONFIGURE; GO EXEC SP_CONFIGURE 'clr enabled' , '1' GO RECONFIGURE; GO -- remember to turn advanced options off again! EXEC sp_configure 'show advanced option', '0' RECONFIGURE GO