Databases
Databases
User databases:
User databases are created by users and used for storing business data.. We can
create user databases by GUI or T-SQL
System Databases:
The system database are some thing that gets created along with your SQL server
installation.. and the system database contains system level information and
these are not meant for storing users/business data
Master
Model
Msdb
TempDB
Resource DB
Distribution Database
Report Server
Report Server TempDb
Master:
Sys.endpoints – this is the table maintains all the end points informations
Select * from Sys.databases – it maitains all the database metadata like names,
id , properties.. etc
Sp_who or sp_who2 – These are the two system stored procedures gives you
open sessions information
With out master database (either master.mdf or master.ldf got corrupted), SQL
Server will not start
When ever we restart sql server, it reads the startup parameters for the master
database locations and then it will check whether the corresponding files exist
or not.. if the files are exist then SQL server will start with out any issues..
We can create an user database with the following simple create command
No it will start the sql server, reason is when you restart sql server.. it has to
create a new tempdb for that model database is required to generate a
template. If the model database is not available, then it will not create tempdb..
so sql server will not start..
MSDB:
SQL Server agent service will be used to implement automations in sql server like
creating jobs and scheduling. MSDB maintains all the information about sql
server agent related like jobs, steps, schedule, operators, alerts, backup
information, restore history ..etc
Yes, sql server will start with out any issues, but agent service will not work.
TempDB: It’s a temporary database in SQL server.. and it maintains all the
intermittent results of a transaction..
A=5
B=10
Final E= a+b+c+D= 40
Select name from sys.databases : This will return all the database names
Yes it will start sql server as when we restart sql server, it will create new
tempdb..
Model:
--Step1: Identify the current location of model database
--right click on model-->properties--> files
use model
go
sp_helpfile
use model
go
sp_helpfile
MSDB:
--Step1: Identify the current location of model database
--right click on model-->properties--> files
use msdb
go
sp_helpfile
select name,physical_name
from sys.master_files
where database_id=4
--Step2:update system catalog with new path for the model database
alter database msdb modify file
(name='MSDBData',filename='C:\sql\MSDBData.mdf')
alter database msdb modify file
(name='MSDBLog',filename='C:\sql\MSDBLog.ldf')
--step3: Stop the sql server
--Step4: copy the files from old to new location
--Step5: Ensure your account have full permissions the files in new location
--Step6: start the sql server
--step7: verify the new location
use msdb
go
sp_helpfile
Tempdb:
--Step2:update system catalog with new path for the model database
alter database tempdb modify file
(name='tempdev',filename='C:\sql\tempdb.mdf')
alter database tempdb modify file
(name='temp2',filename='C:\sql\tempdb_mssql_2.ndf')
alter database tempdb modify file
(name='temp3',filename='C:\sql\tempdb_mssql_3.ndf')
alter database tempdb modify file
(name='temp4',filename='C:\sql\tempdb_mssql_4.ndf')
alter database tempdb modify file
(name='templog',filename='C:\sql\templog.ldf')
Master:
--Step1: Identify the current location of model database
--right click on model-->properties--> files
use master
go
sp_helpfile
select name,physical_name
from sys.master_files
where database_id=1
--Step2:update startup parameters with new path for the master database
--step3: Stop the sql server
--Step4: copy the files from old to new location
--Step5: Ensure your account have full permissions the files in new location
--Step6: start the sql server
--step7: verify the new location
use master
go
sp_helpfile
Informational message
Error messages
Warnings
How to check error log: When your sql server is up and running
sp_cycle_errorlog
Yes,