Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syscomments table uses multiple rows. Why?

Tags:

sql-server

I was writing a script that kept giving me errors. After tracking it down I found that the syscomments table stores its contents in multiple rows if the information gets to long past varchar(8000) i believe.

Why does the syscomments table break the data up into multiple rows instead of 1 single larger row? performance?

like image 382
corymathews Avatar asked Dec 05 '22 03:12

corymathews


1 Answers

syscomments.text is nvarchar(4000) documented here:sys.syscomments (Transact-SQL), which was the best you could do back in the day.

However, you can use the newer sys.sql_modules documented here: sys.sql_modules (Transact-SQL), which has a definition column which is nvarchar(max).

for searching use:

DECLARE @Search nvarchar(500)
SET @Search=N'your text here'
SELECT DISTINCT
    o.name AS Object_Name,o.type_desc --, m.definition
    FROM sys.sql_modules        m 
        INNER JOIN sys.objects  o ON m.object_id=o.object_id
    WHERE m.definition Like '%'+@Search+'%'
    ORDER BY 2,1

if you are pre SQL Server 2005 you can search using the query here: SQL server table population source

like image 198
KM. Avatar answered Jan 09 '23 05:01

KM.