SQL Server Flashcards
This database mostly known as “the SQL Server Agent database” because it stores information of all SQL Agent jobs, configurations and execution histories. Also used to store information about all backups and restores that are executed and histories
msdb database
This database is a template on which all user-created databases are based. All databases must contain a base set of objects known as the database catalog. When a new database is created, the —- is copied to create the requisite objects. Conveniently, objects can be added to the — database.
model database
Ultimately, all temporary database objects are removed when the SQL Server service is restarted.
tempdb database
The —- database is the primary configuration database in SQL Server. It contains information on all the databases that exist on the server, including the physical database files and their locations.
master database
Name the name of the encryption keys in order of hierarchy.
Creating a master key = SMK = Service Master Key.
Creating a certificate in the master database (DMK) (Sometimes ALSO called “master key” = confusing!!)
Creating database encryption key (DEK)
Enable encryption on the database, hence enabling TDK = Transparent Data Encryption (at rest, background encryption).
What are the resources that can be locked in SQL Server? These are all the lock “types” in SQL
RID (Row Identifier), Key (column), Page 8kb, Extent (8 consecutive pages), Table (both data and indexes are locked), and enire DB
What are the lock modes and name each one.
S = Shared Lock = not modifying data (ie: SELECT) or the Schema
U = Update = prevents deadlock = causes a WAIT
X = exclusive = transaction changes and say, oh, I am actually making an update, so cancel the shared lock, cancel the U lock, and make this an X lock = everyone else will experience a WAIT this is my object now
I = Intent
Sch - Schema ie: a table is being dropped
BU = Bulk Update = database lock
describe statements to insert values
INSERT INTO dbo.TableName
VALUES
(‘Fred’,’Andy’,’343’,’453-58-8883’),
describe statements to create a table
CREATE TABLE TableName ( Column1 varchar(20), Column2 varchar(25), Column3 int, SSN varchar(12), )
how to move a table
SELECT * INTO VallesCaldera.dbo.Shippers FROM NorthwindTransfer.dbo.Shippers;
What are the 3 main System Views to use
Catalog Views - metadata, objects
Schema Views - ascii compatible (so version free)
Dynamic Management Views - system state
Types of triggers?
They are type of stored procedure designed to run automatically after 3 types of data modifications. insert, update, and delete modifications (before and after)
cross join and natural join?
cross join is combining 2 tables regardless of whether any columns match; a cross product. A natural means that they are joined based on same name and data types
how to get the row count from a table
SELECT COUNT(*) FROM Table1
how to get the names from a table that start with “J”
SELECT * FROM dbo.MoreInfo WHERE Store LIKE ‘J%’
what are monitoring/tuning tools for a DBA
DMV, extended events, perf mon, standard (pre-built) reports, query execution plan, activity monitor, Query Store
How to get the execution plan without running the query?
Execution Plan ( ctrl L )
a list of all databases on the SQL Server instance, along with information about the database files, their paths, and names
✑ a list of the queries recently executed that use most of memory, disk, and network resources
What should you use?
SQL Server Data Tools
You collect performance metrics on multiple Microsoft SQL Server instances and store the data in a single repository.
You need to examine disk usage, query statistics, and server activity without building custom counters.
SS Data Collector
You need to identify missing indexes.
What should you use?
SS Data Collector
You need to return information about processes that are not idle, that belong to a specific user, or that belong to a specific session.
What should you use?
EXEC SP_who3
You need to examine information about logins, CPU times, and Disk I/O on a particular database in Microsoft Azure. LONGEST QUERIES ON INSTANCE
Activity Monitor
What does sql do with a query plan after constructing?
puts it in the plan cache
what is a transaction that a developer made that is left open=a BEGIN clause with no COMMIT or ROLLBACK
rogue transaction