如何在数据库中找到表ID [英] How can I find table id in a database
问题描述
我有多个数据库.它们都具有相同的结构(相同的表,相同的字段),但名称不同,例如:
数据库1的客户表名称为database1_name客户
和数据库2客户表是database2_name客户
但是它们之间的共同点是表具有相同的id = 18.
我想建立一个可以分别适合两个数据库的数据仓库.为此,我需要使用表ID而不是表名.
所以我的问题是:如何从sql server中的数据库中找到表ID?
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 ?
推荐答案
阅读以下内容: OBJECT_ID [ ^ ]和对象名称 [
Read about: OBJECT_ID[^] and OBJECT_NAME[^]
Example:
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]
此查询将提供有关数据库中表的所有信息
this query will give all information about tables in database
SELECT * FROM sysobjects where TYPE = 'U'
这篇关于如何在数据库中找到表ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!