Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

System databases Vs User created databases

Posted on 2013-01-24
8
Medium Priority
?
423 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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
 

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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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 extract information from SQL Server on Database, Connection and Server properties

963 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