Solved

System databases Vs User created databases

Posted on 2013-01-24
8
409 Views
Last Modified: 2013-01-24
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
0
Comment
Question by:KaranGupta
  • 5
  • 2
8 Comments
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 38813593
-- User Databases
Select *
From sys.databases
Where database_id > 5

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

Author Comment

by:KaranGupta
ID: 38814074
is 1-4 id fixed for system dbs in all versions of sql server. What is the role of sid field
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38814295
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.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38814308
you can also use

SELECT * FROM sys.databases
WHERE owner_sid != 1

Open in new window

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:KaranGupta
ID: 38814313
so what is good practice using sid to identify db or using id what BCUNNEY has suggested
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38814390
either one will work
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 38814413
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38815537
I think it would be fair to split the points with BCUNNEY
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now