System databases Vs User created databases

KaranGupta
KaranGupta used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
-- User Databases
Select *
From sys.databases
Where database_id > 5

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

Author

Commented:
is 1-4 id fixed for system dbs in all versions of sql server. What is the role of sid field
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.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

you can also use

SELECT * FROM sys.databases
WHERE owner_sid != 1

Open in new window

Author

Commented:
so what is good practice using sid to identify db or using id what BCUNNEY has suggested
either one will work
One difference would be

Select *
From sys.databases
Where database_id > 5

will not return aspnetdb

and

SELECT * FROM sys.databases
WHERE owner_sid != 1

will return aspnetdb

aspnetdb is not a system database, it is the default database for using the ASP.NET Application Services
I think it would be fair to split the points with BCUNNEY

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial