September 6, 2012 at 4:15 am
Hi,
Recently i came across something like databaseid. I search for it on internet but could not come up with its practical used.
September 6, 2012 at 5:04 am
Shadab Shah (9/6/2012)
Hi,Recently i came across something like databaseid. I search for it on internet but could not come up with its practical used.
What do you call by "practical used"?
I hope you do refer to database_id from sys.databases (or the one returned by db_id(), which is the same...)
It's used by SQL Server internally to uniquely identify the database within server instance:
September 6, 2012 at 10:38 am
Each database has a unique identifier. The system databases are always 1-4: Master: 1, TempDB: 2, model: 3, msdb: 4. You see get them all with:
select database_id, name from sys.databases
DBAs use the database_id all the time for writing maintenance queries. For example, the query below will get you the size of your databases:
;WITH dbs([dbid],size) AS
(
SELECT database_id,
SUM(size)/128
FROM sys.master_files
GROUP BY database_id
)
SELECT d2.name db,
d1.size [size(mb)]
FROM dbs d1
JOIN sys.databases d2 ON d1.dbid=d2.database_id
I recently drafted a post about this.
-- Itzik Ben-Gan 2001
September 6, 2012 at 10:24 pm
Thank You
September 6, 2012 at 10:26 pm
Shadab Shah (9/6/2012)
Thank You
no problem. 😀
-- Itzik Ben-Gan 2001
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply