Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

System databases Vs User created databases

Hi

I am using following query to get the list of db

select * from sys.databases (or select * from sysdatabases)

My question is how can we know that which db is system database and which one is user created?

Regards
Karan Gupta
Avatar of Barry Cunney
Barry Cunney
Flag of Ireland image

-- User Databases
Select *
From sys.databases
Where database_id > 5

--System Databases
Select *
From sys.databases
Where database_id <= 5
Avatar of KaranGupta
KaranGupta

ASKER

is 1-4 id fixed for system dbs in all versions of sql server. What is the role of sid field
Avatar of YZlat
SID is a system-level identification number.

when an object is created it is assigned an id - SID, that number identifies the object as a securable within SQL Server and then the object is deleted, the id is recycled.
you can also use

SELECT * FROM sys.databases
WHERE owner_sid != 1

Open in new window

so what is good practice using sid to identify db or using id what BCUNNEY has suggested
either one will work
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think it would be fair to split the points with BCUNNEY