SQL语句查询某个数据库中某类表或视图

数据库:Sqlserver
SQL语句:

select * from sysobjects where name like 'Sys%' and (xtype = 'U' or xtype = 'V') order by name

如果筛选的表名称中,包含有下划线_,则用下面语句:

select * from sysobjects where name like 'Sys/_%' ESCAPE '/' and (xtype = 'U' or xtype = 'V') order by name

在Sqlserver的like中下划线类似于通配符%,所以无法使用like '%_%'来匹配下划线,使用转义字符escape。

在语句中,当转义符置于通配符之前时,该通配符就解释为普通字符。上面第二个SQL语句中,‘/’为转义字符,第一、第三个‘%’为通配符。