SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Db_id and object_id
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

waterduck
Aged Yak Warrior

Malaysia
939 Posts

Posted - 03/27/2013 :  03:49:06  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 03/27/2013 :  09:10:41  Show Profile  Reply with Quote
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

Malaysia
939 Posts

Posted - 03/27/2013 :  10:58:38  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 03/27/2013 :  11:52:47  Show Profile  Reply with Quote
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

USA
5071 Posts

Posted - 03/27/2013 :  12:00:24  Show Profile  Visit russell's Homepage  Reply with Quote
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

Malaysia
939 Posts

Posted - 03/31/2013 :  12:49:05  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000