How do I select all the tables name with a particular name in the database?
+6
A:
Either sysobjects
(where type='u'
), or (more correctly) the info-schemas:
SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%CUSTOMER%' -- or "='CUSTOMER'" for exact
If you meant something different, please clarify.
Marc Gravell
2009-04-10 20:53:54
+1 for using INFORMATION_SCHEMA - the SQL standardization way of doing things! :-)
marc_s
2009-04-10 21:50:12
A:
DECLARE @name nvarchar(100)
-- for SQL Server 2008
SELECT * FROM sys.all_objects WHERE name LIKE @name AND type IN ('U', 'S')
-- for others versions
SELECT * FROM dbo.sysobjects WHERE type IN ('U', 'S') AND name LIKE @name
Both scripts are included in Microsoft's scripts.
eKek0
2009-04-10 21:10:36