在我的数据库中,我创建了一些名称中间包含“_”字符的表格,我想找到所有表格。
例如:
Doc_Amit,Doc_Raj,chem_Man etc
我知道查找表名的查询如下:
select * from sys.tables where name like '%%'
但我的问题是我应该在%和%之间写什么,以便我只获得包含通配符'_'的表名???
注意:我使用的是SQL Server 2012
答案 0 :(得分:5)
试试这个 -
SELECT s.name + '.' + o.name
FROM sys.objects o
JOIN sys.schemas s ON o.[schema_id] = s.[schema_id]
WHERE o.name LIKE '%\_%' ESCAPE '\'
AND o.[type] = 'U'
回答评论 -
SELECT *
FROM sys.objects o
->
ALTER VIEW sys.objects AS
SELECT *
FROM sys.objects$
-----------------------------
SELECT *
FROM sys.tables t
->
ALTER VIEW sys.tables AS
SELECT *
FROM sys.objects$ o
LEFT JOIN sys.sysidxstats lob ON lob.id = o.object_id AND lob.indid <= 1
LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = o.object_id AND ds.class = 8 AND ds.depsubid <= 1 -- SRC_INDEXTOLOBDS
LEFT JOIN sys.syssingleobjrefs rfs ON rfs.depid = o.object_id AND rfs.class = 42 AND rfs.depsubid = 0 -- SRC_OBJTOFSDS
LEFT JOIN sys.syspalvalues ts ON ts.class = 'LEOP' AND ts.value = o.lock_escalation_option
WHERE o.type = 'U'
答案 1 :(得分:1)
我得到了最简单的答案,而且更简单!!
select * from sys.objects where name like '%[_]%'