Solved

System databases Vs User created databases

Posted on 2013-01-24
8
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
push and Pull replication 31 47
SQL Syntax 6 30
What Is an Error? 2 25
T-SQL: How to extract records into a new table 7 18
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

749 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