SSMS BasicSQLServAdmin
SSMS BasicSQLServAdmin
SSMS BasicSQLServAdmin
Database Administration
Schema:
an underlying organizational pattern or structure;
conceptual framework
Hospital DB
Application
• Tools for performance analysis, tuning, report generation, and trouble shooting
• The ability deploy high availability configurations of the DBs
• The ability to do data mirroring
• Integration with reporting, BI, and analytic tools
• Integration of R procedures into DB stored procedures
• The ability to cluster multiple DBMSs
• And still more depending on the version and brand of the DBMS
Since this is a basic course in SQL Server, these topics are not covered.
Security Management: User, Groups, and Rights
• Access to data in table/columns is controlled by the security model
• The model is based on three kinds of entities:
• Users / Logins
• Rights / Privileges
• Groups/Roles
• The diagram below lays out the three entities used to manage and enforce DB security:
Group/Role:
• A collection of users
• Can have rights associated with it that
User/Login: users inherit with membership
• Account assigned to an individual*
• A user can belong of one or more
groups
• Can have rights specifically granted
directly to them Right/Privilege:
• Grant or deny the ability to affect a database object
(table, column, index, etc.)
• The four basic rights are listed below plus “no rights”:
• Read
• Write
• Delete
• Execute (does not apply to data entities)
*exception to this rule, account assigned to an application
The SA
object
connection bar properties
server object being displayed
server contents
SSMS comes
with SQL Server
Don’t Panic!
3a. Choose
login type 2. Type name
for new Login
Ignore
Ignore
these 4. Click this
thesefields
for now when you are
fields
done entering
data
Changing a Password
3. Click on “Enabled”
4. Click on “Okay”
Granting/Denying Access to a DB
2. Click on Permissions
3. Click on search
4. Click on browse
5. Check the box next to user you
want to adjust table permissions for
6. Click “OK”
Granting/Denying Access to a Specific Table (cont)
8. Click “OK”
• Security objects can have their characteristics modified directly by using T-SQL
• See commands:
• GRANT
• DENY
• CREATE ROLE
• ALTER ROLE
• DELETE ROLE
• Examples can be found in the documentation
• This allows you to write scripts or functions to carry out security adjustments
• See T-SQL reference at: https://docs.microsoft.com/en-us/sql/t-sql/language-reference
Note: you can only create a database if Creating a New Database
you have been given the right to do so
Ignore these
two options
2. Type name for
new database 3. This can remain <default>
1. On toolbar, click on
View>Properties Window
1. Type in
column name
Ignore
Unicode is a computing industry standard for the consistent encoding, representation, and handling
of text expressed in most of the world's writing systems. Not needed in CRITFC at this time.
Quick Tutorial on Data Types (cont)
Consider the following examples:
• Need to store the number 10,234,443.22
• Store as char(13): 13 bytes = 10 numeric character and 3 punctuations
• Store as float: 4 bytes (but only 7 significant digits -- loss of precision)
• Store as float(53): 8 bytes (15 significant digits – no loss of precision)
• Store as char(50): 13 bytes + 37 unused bytes -- wasted
• So, imagine XYZ’s customer database has 4,000,000 customer names averaging 16
characters. What are the storage demands?:
• For char(256): 4x106 * 256 = 1.024x109
• For vchar(20): not feasible, some names are over 20 characters
• For vchar(MAX): 4x106 * 18 = 72x106 (only 7% of the char(256) size)
• So, choice of data type matters especially for large data bases
• It affects disk space requirements
• It also can have a large effect on performance so chose types with care
Tips on Selecting Types
• Do not store Boolean values as the words “true”/”false”, use the bit data type
• If the exact size a string column should be fixed (example: customer id), use char(n) where n is
the size
• If a field will hold a monetary value, use smallmoney or money depending on how large
number will be
• If a string field will vary in length use varchar(n) where n is the maximum size it can be
• If you need a floating point number and the value is in the range +/- 2*109 and it has 7 or
fewer significant digit use float
• If you need a floating point number and the value is outside of the range +/- 2*109 or it has 8
or more significant digits use real(53)
• If the field holds a time, use time
• If the field holds a date, use date
• If the field holds a timestamp, use timestamp
• If the field holds a date and time use datetime
• If the field holds an integer < +/- 32,768 use a smallint
• If the field holds an integer between +/- 32,768 and +/- 2,147,483,648 use int
• If the field holds an integer between +/- 2,147,483,648 and +/- 9,223,372,036,854,775,808
use bigint
• If the field holds an integer > +/- 9,223,372,036,854,775,808 you are out of luck (or resort to
real(53) but you will loose accuracy)
Note: adding, modifying, or deleting a table is only
possible is you have been granted rites to do so
Deleting a Table
• Backups are usually run in the dead of the night when they do not negatively
affect machine performance for users
• The most straightforward strategy is to backup the entire DBMS each night
• Unfortunately, this is not always possible
• A very large DBMS might take too many hours to complete overnight
• Some corporations have world wide operations so there is no “dead” time
• A common strategy is to use incremental backups
Backup Strategies (cont)
Complete Backup Incremental Backup
The entire DBMS is backed up in one fell swoop The entire DBMS is backed up once a week (over
weekend likely). The other six days an
incremental backup is made capturing only the
things that changed during the last 24 hours.
This is a very common backup strategy.
• Advantages
• Only have to restore a single file
• Disadvantages • Advantages
• Can take a very long time to complete • Incremental backups can be pretty fast
backup • Disadvantages
• First must restore weekly complete backup
and then all the incremental backups to
date
• Potentially longer recovery
Proviso
1. Click on the DB
you wish to backup
2. Click on Tasks
3. Click on BackUp
How to do A Full Backup (cont)
4. Ignore encryption
for now
https://docs.microsoft.com/en-us/sql/relational-
databases/backup-restore/create-a-full-database-backup-sql-
server
Restoring a Full Backup
1. Select DB to
restore and right
click
2. Click on “Tasks”
3. Select
Restore>Database
Restoring a Full Backup
2. Check the
destination DB
and the “restore
to” datetime
Optionally: click on
“Timeline” and
adjust what time
you want to restore
to
Adjusting Recovery Timeline
The Timeline
Interval is a
graphical depiction
Backup activities.
Use it to decide
what point to
restore up to
Pop Quiz
Why might you want not to restore entire backup?
Restoring a Full Backup
Go to:
https://docs.microsoft.com/en-us/sql/relational-databases/backup-
restore/restore-a-database-backup-using-ssms
One More Thing
Data Node
< = 30
16
Rows in
row row row row row
data table
• Suppose you have a table with a column called UCustId (unique customer id) where it
is guaranteed to each and every ID in the column is unique
• Let’s say you have a million customers – so one million rows of data
• You need to find the customer with id 789536
• With a straightforward linear search your worst case scenario is what you want to find
is in the last row and you have to look at each record in the table to find it which
means one million comparisons
• If you build an index on UCustId you worst case is that you have to look at about
log(1,000,000) or 6 comparisons
• If each comparison takes 1 ms (10-3s) the linear search case takes 1000 sec or 16.7 min
to run
• The indexed search takes 6 s or .1 m do it - so it is 167 times faster
• Conclusion: critical data searched often needs to be indexed
• Good example of columning needing an index: primary keys on tables
The Costs Associated with Indexing
• Indexing is not for free
• It can take quite a while to build an index and table may unavailable during at
least part of the time it is being built
• Each time a row is added or removed (and sometimes just modified) the
index has to be updated as well as the table and it can be costly
• Indexes require regular maintenance, i.e., running a defragmentation utility
on them or even rebuilding them with different constraints
• Even with indexes, very large tables may have performance problems and
other actions may need to be taken to reach DB performance goals
• Indexes sometimes go corrupt and have to be rebuilt – which can adversely
affect production while this happens
• When indexes go corrupt, it sometimes can be very hard to diagnose this as
the root cause
• When queries include some kind of string pattern matching, indexes
sometimes cannot be used and the query defaults to linear search
A Few Indexing Guidelines
• Beyond users, rites, and passwords another form of data protection is encryption
• SQL Server can encrypt at two levels:
• You can encrypt individual columns in a table
• You can encrypt an entire database (requires SQL Server 2017 Enterprise Edition)
• Is the encryption easy to crack?
• Encryption is complex subject and we do not have the time to get deep
into this today. It could be the subject of a separate seminar later.
NOTE: the age of the universe is estimated to be about 13.7 billion (13.7 * 109) years…
That’s all folks!