Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have multiple databases.and they all have the same structure (same table,same fields) but different name like in:
database 1 the customer table name is database1_name Customer
and database 2 the customer table is database2_name Customer

but the common thing between them is that the table have the same id =18.
I want to build a datawarehouse that can be adequat to both database separately.and for that, I need to work with table id not table name.
so my question is : How can find table id from a database in sql server ?
Posted
Updated 16-Jun-12 0:17am
v2

Read about: OBJECT_ID[^] and OBJECT_NAME[^]

Example:
SQL
DECLARE @dbid INT
DECLARE @tbid INT

SET @dbid = DB_ID(N'A_TEST')
SET @tbid = OBJECT_ID(N'Table_1', N'U')

SELECT @dbid AS [DatabaseID], DB_NAME(@dbid) AS [DatabaseName],@tbid AS [TableID], OBJECT_NAME(@tbid) AS [TableName]
 
Share this answer
 
Comments
Manas Bhardwaj 18-Jun-12 5:01am    
Correct +5!
Maciej Los 19-Jun-12 16:01pm    
Thank you ;)
Oshtri Deka 19-Jun-12 8:47am    
To the point.5.
Maciej Los 19-Jun-12 16:01pm    
Thank you ;)
Sandeep Mewara 20-Jun-12 8:13am    
5!
this query will give all information about tables in database

SQL
SELECT * FROM sysobjects where TYPE = 'U'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900