SQL SERVER DBA QUEs
SQL SERVER DBA QUEs
SQL SERVER DBA QUEs
The model database, as its name implies, serves as the model (or template)
for all databases created on the same instance. If the model database is
modified, all subsequent databases created on that instance will pick up
those changes, but earlier created databases will not. Note that TEMPDB is
also created from the model every time SQL Server starts up.
SQL profiler is the SQL Server utility you can use to trace the traffic on the
SQL Server instance. Traces can be filtered to narrow down the transactions
that are captured and reducing the overhead incurred for the trace. The trace
files can be searched, saved off, and even replayed to facilitate
troubleshooting.
There are 3 recovery models available for a database. Full, Bulk-Logged, and
Simple are the three recovery models available.
1) restore the database ( right click on databases > Restore ( it can be in the
same instance )) with a differente name.
2) In this new database ( The restored one ) , open tables , search the table
you've deleted, right button, Script table as > CREATE TO. This will crate a Script.
Execute it on the old database ( the one you have deleted the table). It will
create the structure of that table.
3) Now you can do something like this:
When you do "Tasks -> Shrink" from the GUI it actually issues a DBCC
SHRINKDATABASE command behind the scenes. Try it. When the dialog box
comes up, don't click the "OK" button. Instead, click the "Script" button. You'll
see the command in a query window. Combine that with a query on
sys.databases (leave out master and msdb), and you can make a script to
shrink all of the databases.
For example (taken from jcolebrand's comment):
SELECT
'USE [' + d.name + N']' + CHAR(13) + CHAR(10)
+ 'DBCC SHRINKFILE (N''' + mf.name + N''' , 0, TRUNCATEONLY)'
+ CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
FROM
sys.master_files mf
JOIN sys.databases d
ON mf.database_id = d.database_id
WHERE d.database_id > 4;
If the two join inputs are not small but are sorted on their join column (for
example, if they were obtained by scanning sorted indexes), a merge join is
the fastest join operation. If both join inputs are large and the two inputs are
of similar sizes, a merge join with prior sorting and a hash join offer similar
performance. However, hash join operations are often much faster if the two
input sizes differ significantly from each other. For more information, see
Understanding Merge Joins.
Hash joins can efficiently process large, unsorted, non indexed inputs.
SQL Server has three types of replication: Snapshot, Merge, and Transaction.
Snapshot replication creates a snapshot of the data (point-in-time picture of
the data) to deliver to the subscribers. This is a good type to use when
the data changes infrequently, there is a small amount of data to
replicate, or large changes occur over a small period of time.
Transaction replication also begins with a snapshot only this time changes
are tracked as transactions (as the name implies). Changes are replicated
from publisher to subscriber the same as they occurred on the publisher, in
the same order as they occurred, and in near real-time. This type of
replication is useful when the subscriber needs to know every change that
occurred to the data (not point-in-time), when the change volume is high, and
when the subscriber needs near real-time access to the changes.
What is DBCC?
DBCC statements are Database Console Commands and come in four flavors:
1. Maintenance
2. Informational
3. Validation
4. Miscellaneous
Maintenance commands are those commands that allow the DBA to perform
maintenance activities on the database such as shrinking a file.
In a clustered index, the leaf level pages are the actual data pages of the
table. When a clustered index is created on a table, the data pages are
arranged accordingly based on the clustered index key. There can only be
one Clustered index on a table.
In a Non-Clustered index, the leaf level pages do not contain data pages
instead it contains pointers to the data pages. There can multiple non-
clustered indexes on a single table.
should my PK be clustered?
which column(s) will be the best key for my clustered index?
PK and Clustered index are 2 differences things:
Ans:
Fill Factor is a setting that is applicable to Indexes in SQL Server. The fill
factor value determines how much data is written to an index page when it is
created/rebuilt.
Where do you find the default Index fill factor and how to
change it?
The easiest way to find and change the default fill factor value is from
Management Studio, right-click the SQL Server, and choose properties. In the
Server Properties, choose Database Settings, you should see the default fill
factor value in the top section.
You can change to the desired value there and click OK to save the changes.
The other option for viewing and changing this value is using.
CTEs...
I have a database and want to move the .mdf and .ldf files to another
location. But I do not want to stop the MSSQLSERVER service, and I do
not want to export to another server.
MDF and LDF files are protected and cannot be moved while the database is
online.
If you don't mind stop the database from working, then you can DETACH it,
move the files and then ATTACH it.
This will list all "most recent" restores for each database on your server:
WITH LastRestores AS
(
SELECT
DatabaseName = [d].[name] ,
[d].[create_date] ,
[d].[compatibility_level] ,
[d].[collation_name] ,
r.*,
RowNum = ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY r.[restore_date]
DESC)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] =
d.Name
)
SELECT *
FROM [LastRestores]
WHERE [RowNum] = 1
Make sure you don't have dependencies like database snapshots on the db
you want to remove. Though, the error message would look otherwise. Are
you sure that there is no hidden process that is connecting to your database?
A good approach would be to run a script which kills all sessions and
immediately after rename the database to another name and then drop
database.
Then execute - sp_lock that will show all the locks on the instance along with
spid and dbid.
Kill the spids with the dbid that you are trying to offline or drop.
You have been receiving alerts indicating that the disk space used by one of
your critical database servers is running out of space. How would you go
about identifying which databases and files are using the most disk space,
and what steps would you take to free up space without affecting the server
and databases operations?
4.goldengate components?
8.tuning in rac?
10.optimizer statistics?