Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Db_id and object_id

Author  Topic 

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-03-27 : 03:49:06
Hi,
this might look stupid but will db_id and object_id crash one day? What i trying to say that, will the value return might get same in any possible?

for example:
select DB_ID(N'AdventureWorksDW2012')
return 1
select OBJECT_ID(N'AdventureWorksDW2012.dbo.DimAccount')
return 1

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-27 : 09:10:41
It certainly is possible. When I run the query "select MIN(object_id) from sys.objects" on my test server it returns 3. The object name is sysrscols. On my server db_id = 3 is model database.
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-03-27 : 10:58:38
Sorry, my bad. further clarification
select object_id(table_name) from INFORMATION_SCHEMA.TABLES

database id vs table id
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-27 : 11:52:47
I don't know the answer to this - but I would think that the algorithms ued to determine the range of values for user tables is something internal to Microsoft and it would not be a good idea to rely on it being in any particular range. For example, see this page regarding temp tables http://blogs.msdn.com/b/psssql/archive/2012/09/09/revisiting-inside-tempdb.aspx
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-03-27 : 12:00:24
If you're asking if object_id() and db_id() can return the same value, then the answer is a definite yes.

What are you trying to accomplish? Why do you care what the object_id or database_id is? You can always derive it when needed to pass as a parameter.

If you're creating objects SQL Server will assign object ids.

If you're searching for objects, you can identify them by name and/or type.
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-03-31 : 12:49:05
im just curious about is there any unique identifier for database and table and will they crash each other? =P
Go to Top of Page
   

- Advertisement -