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
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
how do you prevent data corruption
enable checksum page and run DBCC commands such as CHECKDB, CHECKCATALOG, CHECKALLOC
how can you view the top resource consuming sessions
right click instance name, reports, standard reports, and a list appears
explain each checkpoint type
automatic, internal, manual, indirect All of these are based on Recovery Time
An — —- occurs each time the number of log records reaches the number the Database Engine estimates it can process during the time specified in the recovery interval server configuration option.
automatic checkpoint
This can be configured recovery time database options.
Indirect checkpoints
what is this; in the course of a transaction, new rows are added or removed by another transaction to the records being read
phantom transaction
what is a transaction wrap arround
the database transaction counter is cyclic, and the database can grow the transaction number until they have to return to 0, and rather than do that, the database shuts down to maintain data integrity
To discover what is preventing log truncation in a given case, use —-
the log_reuse_wait and log_reuse_wait_desc columns of the sys.database catalog view
what are the steps if the log is full and db has 9002 error (in read only mode)
Perform a trans log backup, if not enough space for that then change the recovery plan to simple. (After one of those, shrink the log file size (make sure to select “log file” and NOT database) AND take a full backup because there are now no trans logs. Another option is to change the log file size to “Unlimited” if there is a limit set (percentage or max size in MB. Also, an additional log file can be added.
Keys that all could be a PK are;
Candidate Keys
Entities
are the tables (cats, dogs, users)
Attributes
are the columns; payment type, black or grey cat, been to the vets
a primary key that is a database produced random number
surrogate key
a primary key that is a real world attribute, like email address, social security number
natural key