SQL 2005 : Master,modal,msdb,tempdb - sql-server-2005

I have question regarding sql system database that what purpose of these database of msdb and msdb.
Thanks in advance.

Check MSdn : System Databases and Data : http://msdn.microsoft.com/en-us/library/aa174522%28v=sql.80%29.aspx
Microsoft® SQL Server™ 2000 systems have four system databases:
* master
The master database records all of the system level information for a SQL Server system. It records all login accounts and all system configuration settings. master is the database that records the existence of all other databases, including the location of the database files. master records the initialization information for SQL Server; always have a recent backup of master available.
* tempdb
tempdb holds all temporary tables and temporary stored procedures. It also fills any other temporary storage needs such as work tables generated by SQL Server. tempdb is a global resource; the temporary tables and stored procedures for all users connected to the system are stored there. tempdb is re-created every time SQL Server is started so the system starts with a clean copy of the database. Because temporary tables and stored procedures are dropped automatically on disconnect, and no connections are active when the system is shut down, there is never anything in tempdb to be saved from one session of SQL Server to another.
By default, tempdb autogrows as needed while SQL Server is running. Unlike other databases, however, it is reset to its initial size each time the database engine is started. If the size defined for tempdb is small, part of your system processing load may be taken up with autogrowing tempdb to the size needed to support your workload each time to restart SQL Server. You can avoid this overhead by using ALTER DATABASE to increase the size of tempdb.
* model
The model database is used as the template for all databases created on a system. When a CREATE DATABASE statement is issued, the first part of the database is created by copying in the contents of the model database, then the remainder of the new database is filled with empty pages. Because tempdb is created every time SQL Server is started, the model database must always exist on a SQL Server system.
* msdb
The msdb database is used by SQL Server Agent for scheduling alerts and jobs, and recording operators.

Related

Syncing data between 2 SQL Server tables

I have 2 servers. One used for backup as well as sharing with other external users and the other for live queries internally.
At the moment, on the backup database, the existing table is dropped and new table is added using the below code:-
DROP TABLE [dbo].[test]
SELECT * INTO test FROM [remote server].[remote database].[dbo].[remote table];
Is there another method instead of dropping and adding tables. Ideally, something that looks for any changes and syncs them using SQL Server Management Studio.
Edit:
My server is Express Edition and remote is SQL Standard
If you want to sync two tables in simplex communication way(One Directional) then you should go with transaction replication.
Sync will be performed on transaction commit for particular row.

Can't view or edit tempdb in Azure SQL Database

I have a database on Azure using the SQL Database (PaaS) offering.
I can't see or access the tempdb nor can I create it.
If I try to create the database I get the following error:
Msg 1801, Level 16, State 3, Line 10
Database 'tempdb' already exists. Choose a different database name.
Does anyone know what's going on here?
TempDB on Azure SQL Database is created and managed by Azure platform and the TempDB capacity has a limit in size based on the Azure SQL Database tier.
Hope this helps.
I am going to up tick Alberto since he is right about the service handling this system database.
I guess my main question is why are you using [tempdb]?
Before there was a push to the cloud, lazy SQL developers would create tables in [tempdb]. These tables should have been placed into a user defined staging database or schema.
Let's see if local/global temporary tables and user defined tables in [tempdb] are allowed.
-- local temp table
select 'Fee Fie Foo Fumb' as rhymes into #a
go
-- show the data
select * from #a
go
-- show my local tables
select * from tempdb.sys.tables
go
The expected results are shown below. Local and global temp tables are supported.
If we try the following create statement within Azure SQL database, the service is smart enough to know that you can not use [tempdb] directly.
Now, back to my first question.
Why are you trying to use and/or modify [tempdb]??
In rebuttal to Alberto, global temporary tables are now supported in Azure. The database being referenced by the session is a Basic tier (b0) level.

Does Oracle use temp tables during backup procedures

Does Oracle make use of temp tables during backup procedures?
This has brought up many conversations in the break room, but we are limited in our expertise.
I'm pretty sure, please correct me if i am wrong, but to fully qualify for ACID - you need a way to store the data when the database is taken offline, even for a moment.
SQL Server writes to the transaction log, then will catch up after the DB comes back online - but i am not sure if Oracle follows the same idea.
thank you
If you mean with "Backup" that a Tablespace or the whole database is taken to backup-mode with ALTER TABLESPACE tbname BEGIN BACKUP or ALTER DATABASE BEGIN BACKUP the database is not offline but the tablespace resp. the datafiles on the disk are not written into.
This is necessary to prevent a backup of the datafiles in an inconsistent state (fractured block). The blocks changed (called "dirty") during this process are written to the redo-logfile and applied later when ALTER DATABASE END BACKUP is issued.
Backups done with RMAN (Recovery Manager) dont need backup mode at all.

Can you please tell importance of default databases provided by SQLserver?

In Sqlsever Enterprise manager, there are some default databases are provided like tempdb and etc. What is significance of those databases?
TempDB is used for temporary work in SQL Server. Anytime you create a temp table that storage is done inside of TempDB. Here is a very good article from MSDN
Here are some points referenced from the MSDN:
The tempdb system database is a global resource that is available to all users connected to the instance of SQL Server and is used to hold the following:
•Temporary user objects that are explicitly created, such as: global or local temporary tables, temporary stored procedures, table variables, or cursors.
•Internal objects that are created by the SQL Server Database Engine, for example, work tables to store intermediate results for spools or sorting.
•Row versions that are generated by data modification transactions in a database that uses read-committed using row versioning isolation or snapshot isolation transactions.
•Row versions that are generated by data modification transactions for features, such as: online index operations, Multiple Active Result Sets (MARS), and AFTER triggers.
Operations within tempdb are minimally logged. This enables transactions to be rolled back. tempdb is re-created every time SQL Server is started so that the system always starts with a clean copy of the database. Temporary tables and stored procedures are dropped automatically on disconnect, and no connections are active when the system is shut down. Therefore, there is never anything in tempdb to be saved from one session of SQL Server to another. Backup and restore operations are not allowed on tempdb.
There is also the master database (holds information about all databases), Model database, MSDB (stores information on the sql agent, dts, jobs, etc).
More info here as well
MASTER - This keeps all server-level information, and meta-data about all databases on the server. Don't lose this :)
MSDB - Holds information about SQL Agent jobs and job run history
TEMPDB - Used as a temporary "work space" for temporary tables and lots of other stuff (like sorting and grouping)
MODEL - When you create a new, blank database, it makes a copy of MODEL as a template
DISTRIBUTION - (You will only see this on servers where you have set up replication) Holds records pending for replication.
SQL Server uses tempdb to store internal objects such as the intermediate results of a query. You can get more details here.

How tempDB works?

I am trying to understand the tempDB and following are the doubts popping in my mind.
What is the lifetime of data in tempDB? Say a query is doing some Order By and uses tempDB for performing that. After this query finishes, someone else also executes a query which utilizes the tempDB. Will the second query find records written by first query in the tempDB or will they be deleted?
Are there any visible tables created inside the tempDB by the Sql Engine? How can I know which temporary table is created because of this query? Is there any naming convention followed by the Sql engine for naming these temporary tables?
I am new to tempDB so please pardon me for asking such silly (if at all) questions :-)
It will be very nice if someone can point me to a good resource which can help me learn about tempDB.
Temp table is stored in tempdb until the connection is dropped (or in the case of a global temp tables when the last connection using it is dropped). You can also (and it is a good practice to do so) manually drop the table when you are finished using it with a drop table statement.
No, others cannot see your temp tables if they are local temp tables (They can see and use global temp tables) Multiple people can run commands which use the same temp table name but they will not be overlapping in a local temp table and so you can have a table named #test and so can 10,000 other users, but each one has its own structure and data.
You don't want to generally look up temp tables in tempdb. It is possible to check for existence, but that is the only time I have ever referenced tempdb directly. Simply use your temp table name. Example below of checking for existence
IF OBJECT_ID('TempDB.dbo.#DuplicateAssignments') IS NOT NULL
BEGIN
DROP TABLE #DuplicateAssignments
END
You name temp tables by prefacing the name with # (for local tables the ones you would use 999.9% of the time) and ## for global temp tables, then the rest of the name you want.
There's a few MSDN articles that are probably the best source of information on the tempDB database in SQL Server.
tempdb Database
The tempdb system database is a global
resource that is available to all
users connected to the instance of SQL
Server and is used to hold the
following:
Temporary user objects that are explicitly created, such as: global or
local temporary tables, temporary
stored procedures, table variables, or
cursors.
Internal objects that are created by the SQL Server Database Engine, for
example, work tables to store
intermediate results for spools or
sorting.
Row versions that are generated by data modification transactions in a
database that uses read-committed
using row versioning isolation or
snapshot isolation transactions.
Row versions that are generated by data modification transactions for
features, such as: online index
operations, Multiple Active Result
Sets (MARS), and AFTER triggers.
Operations within tempdb are minimally
logged. This enables transactions to
be rolled back. tempdb is re-created
every time SQL Server is started so
that the system always starts with a
clean copy of the database. Temporary
tables and stored procedures are
dropped automatically on disconnect,
and no connections are active when the
system is shut down. Therefore, there
is never anything in tempdb to be
saved from one session of SQL Server
to another. Backup and restore
operations are not allowed on tempdb.
There's also tempdb and Index Creation, this blog post along with Working with tempdb in SQL Server 2005 which states:
The SQL Server system database, tempdb, has undergone a number of changes in SQL Server 2005. There are new tempdb usages and internal optimizations in SQL Server 2005; tempdb architecture is mostly unchanged since SQL Server 2000.
The tempdb system database is very similar to a user database. The main difference is that data in tempdb does not persist after SQL Server shuts down.
The temporary tables created in TempDB are dropped when the query is completed.
I'm not sure on this (I would have to try it), but I think theoretically ALL tables created in TempDB are visible, although only the user that created the table has permission to access it.