ict.ken.be

 

Posts in Category: SQL Server

Find stored procedures and views that contain a text 

Categories: SQL Server

SELECT o.name, o.xtype
FROM syscomments c (NOLOCK)
INNER JOIN sysobjects o (NOLOCK) ON c.id=o.id
WHERE c.TEXT LIKE '%userpersontype%'

Objects recently created 

Categories: SQL Server

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('U')
order by crdate desc

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('V')
order by crdate desc

select top 100 *
from sysobjects o (NOLOCK)
where xtype in ('P')
order by crdate desc

Replace in ntext (eg. exports of Messagent) 

Categories: Messagent SQL Server

select cast(replace(cast(xml as nvarchar(max)),'old@mail.be', 'new@mail.be') as ntext) 
from channels
where xml like '%old@mail.be%'

/*
update channels
set xml = cast(replace(cast(xml as nvarchar(max)),'old@mail.be', 'new@mail.be') as ntext)
where xml like '%old@mail.be%'
*/

Space used by database objects 

Categories: SQL Server
CREATE TABLE #foo(
name varchar(128),
rows int,
reserved varchar(128),
data varchar(128),
index_size varchar(128),
unused varchar(128)
)
DECLARE @objectName nvarchar(128)
DECLARE cursorTables CURSOR FOR
 SELECT so.name
 FROM sysobjects so (nolock), sysindexes si (nolock)
 WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name)
 GROUP BY so.name 
 ORDER BY MAX(si.rows) DESC
OPEN cursorTables
FETCH NEXT FROM cursorTables INTO @objectName
WHILE @@FETCH_STATUS = 0
BEGIN
 INSERT INTO #foo
 EXEC ('sp_spaceused ' + @objectName)
 FETCH NEXT FROM cursorTables INTO @objectName
END
CLOSE cursorTables
DEALLOCATE cursorTables
SELECT * FROM #foo
DROP TABLE #foo

SQL Server Version 

Categories: SQL Server

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

Page 4 of 5 << < 1 2 3 4 5 > >>