Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System databases Vs User created databases

Posted on 2013-01-24
8
Medium Priority
?
421 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

722 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