01 Monitor and Administer Database
01 Monitor and Administer Database
DATABASE ADMINISTRATION
LEVEL – IV
• All logins that are members of the sysadmin fixed server role have been removed by mistake.
• All Windows Groups that are members of the sysadmin fixed server role have been removed by mistake.
• The logins that are members of the sysadmin fixed server role are for individuals who have left the company
or who are not available.
Microsoft SQL Server and the Microsoft Windows operating system provide utilities that let you view the current
condition of the database and to track performance as conditions change.
Activity Monitor runs queries on the monitored instance to obtain information for the Activity Monitor
display panes. When the refresh interval is set to less than 10 seconds, the time that is used to run these
queries can affect server performance.
To view the Activity Monitor, a user must have VIEW SERVER STATE permission. To view the Data File
I/O section of Activity Monitor, you must have CREATE DATABASE, ALTER ANY DATABASE, or
VIEW ANY DEFINITION permission in addition to VIEW SERVER STATE.
A data dictionary is a collection of descriptions of the data objects or items in a data model for the benefit
of programmers and others who need to refer to them. I.e. Itis a set of information describing the contents,
format, and structure of a database and the relationship between its elements, used to control access to and
manipulation of the database.
When developing programs that use the data model, a data dictionary can be consulted to understand
where a data item fits in the structure, what values it may contain, and basically what the data item means
in real-world terms.
* Most DBMS keep the data dictionary hidden from users to prevent them from accidentally destroying its
contents.
Data integrity is a constraint which used to ensure accuracy and consistency of data in a database by validating
the data before getting stored in the columns of the table.
Data integrity refers to the overall completeness, accuracy and consistency of data in according to business
requirements
2.3 Introduction to integrity constraints
This is concerned with the concept of primary keys. The rule states that every table must have its own primary
key and that each has to be unique and not null.
This is the concept of foreign keys. A foreign key is a column (or columns) that references a column (most
often the primary key) of another table. The purpose of the foreign key is to ensure referential integrity of
the data. In other words, only values that are supposed to appear in the database are permitted.
. The rule states that the foreign key value can be in two states. The first state is that the foreign key value
would refer to a primary key value of another table, or it can be null. Being null could simply mean that
there are no relationships, or that the relationship is unknown. Referential integrity is a feature provided
by relational DBMS that prevents users from entering inconsistent data.
Referential integrity ensures that every value in a child key; the foreign key of the child table, has a
corresponding value in the parent key; the primary key or unique index of the parent table. Referential
integrity is enforced between tables using the parent-child relationship established with foreign keys. DB
Maker has automatic support for referential integrity constraints between tables through the definition of
foreign keys. When adding a record to a child table, the value in the child key must also exist in the parent
key. Similarly, when deleting a record from the parent table, all records in the child key with the same value
must be deleted first.
Referential actions provide a means to update or delete a parent key when referential integrity would not
normally allow it such as when a parent key is referenced by a child key. The referential actions define the
operation DB Maker should perform on all matching rows in the child key when updating or deleting a
parent key referential actions for both updates and deletes: CASCADE, SETNULL, SET DEFAULT, and
NO ACTION.
CASCADE performs an update or delete on all matching values in the child key when updating or
deleting the parent key. This will set the value of the child key to the same value as the parent key when a
row in the parent key updates, or will delete all matching values in the child key with the same value as
the parent key when deleting a row in the parent key.
SET NULL sets all matching values in the child key to NULL when you update or delete a row in the
parent key. You cannot use the SET NULL action when the child key was defined with the NOT NULL
constraint.
SET DEFAULT sets all matching values in the child key to the default value of the column when you
update or delete a row in the parent key. You cannot use the SETDEFAULT action when the default
value is NULL and the child key was defined with the NOT NULL constraint.NO ACTION enforces
normal referential integrity rules. DB Maker will use NO ACTION by default.Columns in a foreign key
may contain null values. If a foreign key contains a null value, it satisfies referential integrity
automatically
Business rules may dictate/state that when a specific action occurs further actions should be triggered.
For example, deletion of a record automatically writes that record to an audit table.
2.4 Create and design indexes and multiple-field keys
2.4.1 What is index?
An indexis a separate physical data structure that enables queries to access one or more data rows fast.A
database index is a separate physical data structure that improves the speed of data retrieval operations
on a database table at the cost of additional writes and the use of more storage space to maintain the
extra copy of data. Indexes are used to quickly locate data without having to search every row in a
database table every time a database table is accessed. Indexes can be created using one or more
columns of a database table, providing the basis for both rapid random lookups and efficient access of
ordered records.
Why Use Indexes? Two primary reasons exist for creating indexes in SQL Server:
Narrower indexes take less space, require less time to process, which in turn means the query will
run faster.
For indexes covering multiple columns, the order of the columns in the index is important.
Make sure the column you are building an index for is declared NOT NULL
This can decrease the size of the index, which in turn will speed up the query
A simple index is an index on a single column, while a composite index is an index on two or more columns.
- You should create indexes on columns that are used frequently to join tables.
- You should create indexes on columns that are used frequently in ORDER BY clauses.
- You should create indexes on columns that have few of the same values or unique values in the table.
- You should not create indexes on small tables (tables that use only a few blocks) because a full table scan
may be faster than an indexed query.
- If possible, choose a primary key that orders the rows in the most appropriate order.
2.4.3 Create an index
. Indexes can be created to order the values in a column in ascending or descending sequence.
You may drop an index permanently when it is no longer useful or temporarily. If the index is harming or
not helping performance, it could be dropped.
Indexes may slow down the loading of data because they must be maintained during the data load process.
For high performance loads, an index could be dropped for the duration of a load and then recreated.
To delete an index by using Object Explorer, you can follow the steps as shown below:
In Object Explorer, expand the database that contains the table on which you want to delete an index.
In Object Explorer, expand the database that contains the table on which you want to delete an index.
- Expand Databases, expand the database that contains the table with the specified index, and then expand
Tables.
- Expand the table in which the index belongs and then expand Indexes.
› Expand Databases, expand the database in which the table belongs, and then expand Tables.
› Expand the table in which the index belongs and then expand Indexes.
› Right-click the index that you want to modify and then click Properties.
› In the Index Properties dialog box, make the desired changes. For example, you can add or remove
a column from the index key, or change the setting of an index option.
If the values in a single common key field are insufficiently unique to accurately join or relate two tables,
you need to use multiple common key fields in combination. In the examples below, the composite primary
key consists of two columns, Birth_Date and Social_Security_Number.
• Tables • Connections
•
Data Rows • Entire Systems
There are also many types of locks such as shared locks, transaction locks, DML locks, and backup-recovery locks
This section describes the storage structures of your database, and explains how to monitor and manage the amount
of storage that is in use and available for the database and its backups. It contains the following topics:
Training, Teaching and Learning Materials (TTLM)
The modification of data that is already in the database is referred to as updating. You can update individual
rows, all the rows in a table, or a subset of all rows. Each column can be updated separately without
affecting the other columns.
SET{column_name={expression|default|null}}|
WHERE{search condition}
Use the UPDATE statement to change single rows, groups of rows, or all of the rows in a table.
Before you can connect to SQL Server, an administrator of the SQL Server installation must give you
permission to connect. In a Windows authentication setup, the administrator would either allow your Windows
account or a group that contains your Windows account to connect to SQL Server.
9
TLM Development Manual te: January, 2020
The following example creates a login for a particular user ID and assigns a password. The MUST_CHANGE option
requires users to change this password the first time they connect to the server.
. In SQL Server, open Object Explorer and expand the folder of the server instance.
. Expand security folder, Right-click on login folder, and then select New Login.
Training, Teaching and Learning Materials (TTLM)
. Click on the General, and enter the name of a Windows user in the Login name box.
. Select Windows Authentication, and then Click OK.
To create a SQL Server login that uses SQL Server Authentication using wizard
* In SQL Server, open Object Explorer and expand the folder of the server instance.
* Expand security folder, Right-click on login folder, and then select New Login.
* Click on the General, and enter the name of a Windows user in the Login name box.
* Select SQL Server Authentication. However, Windows Authentication is the more secure option.
* Enter a password for the login.
* Select the password policy options that should be applied to the new login, and then Click OK.
- In general, enforcing password policy is the more secure option.
To create a SQL Server login that uses SQL Server Authentication using T-SQL code
A login only can only be granted authorization to objects in a database if a database user
has been mapped to the login. A special user, guest, exists to permit access to a
database for logins that are not mapped to a specific database user.
• Create database
Database Level
• Query and modify data
• Create objects
2. Creating Schemas
InSQL Server, schema is an object that conceptually holds definitions for database objects such as tables,
views, stored procedures, etc. The main advantage of creating a schema is that you can grant permissions
to database objects by using a single CREATE SCHEMA statement.
Note: Windows Authentication mode is the default and recommended authentication mode.
Configuring SQL Server Authentication Modes
To select or change the server authentication mode, follow these steps:
* In SQL Server, right-click on a desired SQL Server, select Properties and then Select Security
* Select the desired server authentication mode under Server Authentication and then click
OK.
These roles, available for anyone to use across the server, can perform the following tasks:
• SYSADMIN –Performany action on the server.
• SECURITYADMIN –Manage server level permissions.
• SERVERADMIN –Manage server configurations and start/stop services.
• PROCESSADMIN –Kill processes running on the instance.
• SETUPADMIN –Add/remove linked servers.
• BULKADMIN –Able to run BULK INSERT and execute bulk operations.
• DISKADMIN –Manage server disk files. DBCREATOR –Create, alter, drop, and restore databases.
• PUBLIC –Generic role that all users member of are a
.Server roles are static objects. They contain groups of actions that operate at the server level rather than at
the database level. When creating a new login, you could assign these server roles to it if you wanted the
login to carry out server actions as well as any database-related actions, if required.If your Windows
account belongs to the BUILTIN/Administrators group, then it automatically belongs to the sysadmin
server role. You can check this yourself by highlighting the sysadmin server role, right-clicking it, and
selecting Properties to bring up the dialog box shown in Figure below . You should see
BUILTIN/Administrators listed. As more logins are created, they can be added to this role via the Add button.
-To add user u1 to be the member of student role, EXECUTE sp_addrolemember ‘student’,’u1’
-To add user u1 to be the member of fixed database role, EXECUTE sp_addrolemember
Example:sp_addrolemember ‘db_accessadmin’,’u1’
2. Granting Permissions
The GRANT statement is used to give privilege to users or roles.
GRANT –give user privileges on an object. Does not override implicit denied permissions
Training, Teaching and Learning Materials (TTLM)
Note: if the permission is given via the [WITH GRANT OPTION], all users in the TO clause can themselves pass
on the privilege to other users.
The privileges that can be granted are divided into four groups:
• Column privileges relate to one specific column of a table for example, the privilege to update the
values in the AMOUNT column of the PENALTIES table with UPDATE statements.
• Table privileges relate to all data of one specific table for example, the privilege to query all the
data of the PLAYERS table with SELECT statements.
• Database privileges relate to all tables of one specific database for example, the privilege to create
new tables in the existing TENNIS database.
The GRANT command grants access privileges on database objects to individualusers. Only the object owner,
a DBA or a SYSADM may execute the command.Object privileges control which database objects a user can
access and the actions theycan perform. There are seven object privileges: SELECT,
INSERT, DELETE,UPDATE, INDEX, ALTER, and REFERENCE. The keywords ALL and ALLPRIVILEGES
can also be used to simultaneously grant privileges on an object.
•SELECTprivilege is used to select data in a database object, applies to the entireobject, and cannot
•INSERTprivilege is used to insert new data into a database object. The privilegecan also be restricted
to specific columns.
•DELETEprivilege is used to delete data from a database object, applies to theentire object and
•UPDATEprivilege is used to update data in a database object. The privilege canalso be restricted to specific
columns.
Training, Teaching and Learning Materials (TTLM)
•INDEXprivilege is used to create an index on a database object, applies to theentire object, and cannot
•ALTER privilege is used to alter the schema of a database object, applies to theentire object and cannot
•REFERENCE privilege is used to create referential constraints, such as foreignkeys, on a database object.
User privileges relate to all databases that are known to SQLfor example, the privilege to remove existing databases
or to create new ones.
Syntax
Notedatabase privilege also have the privilege of create, drop and lock table privilege
3. DENY –remove user privileges on an object overrides any implicit permission grants
Examples:
• deny select on customers to test
• deny insert on orders to test
test
• deny delete, update on customers to
4. Revoking Permissions
The REVOKE statement withdraws or revokes privileges from a user without deleting that user from the
USERS table. This statement has the opposite effect of the GRANT statement.
REVOKE–resets user privileges on an object In other words, removes explicit grant or deny Examples:
• revoke select on customers to test
• revoke insert on orders to test
revoke delete,updateon customers to test
A principalis any individual, group, or process that can request access to a protected resource and
be granted permission to access it.
The role includes the development and design of database strategies, system monitoring and improving database
performance and capacity, and planning for future expansion requirements. They may also plan,
A System Administrator is generally responsible for all parts of the computer network, such as user accounts,
computer accounts, domain trusts, email accounts, etc.
The System Administrator is probably specialized in the network server operating systems and user
administration; where as a Database Administrator will be highly specialized with the specific database server
and client.
A network administrator maintains network infrastructure such as switches and routers, and diagnoses problems
with these or with the behavior of network-attached computers.
For example: To create a table, a user must be authorized to create tables; to alter a table. Authorization
In computing systems, authorization is the process of determining which permissions a person or system is
supposed to have. In multi-user computer systems, a system administrator defines which users are allowed
access to the system, as well as the privileges of use for which they are eligible (e.g., access to file
directories, hours of access, amount of allocated storage space).
Privileges
A privilege is a permission to perform an action or a task. Authorized users can create objects, have access
to objects they own, and can pass on privileges on their own objects to other users by using the GRANT
statement. Privileges may be granted to individual users or roles (groups).
Training, Teaching and Learning Materials (TTLM)
You can apply five different kinds of user privileges. A user may be able to view, delete, insert, or update
information in a table or view.
A user who has no privileges to a table is not able to use the table at all. Role
A role is a group of privileges that can be granted to users as one unit. You can create roles and assign
users to certain roles. A single user may have more than one role assigned, and a single role may have more
than one user assigned. All roles are granted to users with the GRANT ROLE statement.
Monitoring network server log-in log file for illegal log-in attempts or for security breach
Network monitoring
The term network monitoring describes the use of a system that constantly monitors a computer network
for slow or failing components and that notifies the network administrator in case of outages. Network
Server Monitoring allows a network administrator to track the health of network servers in real time.
Network Server Monitoring can identify servers that are in danger of malfunctioning before a malfunction
occurs so that the administrator can proactively repair the server. Network Server Monitoring allows a single
administrator to maintain many remote network servers.
Members of this group can perform server management tasks such as creating, changing, and deleting
shared printers, shared directories, and files. They can also backup and restore files, lock the server console
and shutdown the system, but they cannot modify system policies or start and stop services.
2. Click Start, point to Administrative Tools, and click Active Directory Users and Computers.
3. In the left pane of the Active Directory Users and Computers window, expand the contents of the newly
created Active Directory domain.
o Type your first and last names in the First name and Last name fields, respectively.
o In the User logon name field, type a name that will be used to log on to the Active Directory
domain. For example:
Training, Teaching and Learning Materials (TTLM)
7. Specify an arbitrary password for the domain administrator account and click Next
Now you should include the newly created account in the Domain Admins group, which will allow this account
to perform administrative tasks in the domain context. To this effect, do the following:
9. In the Active Directory Users and Computers window (Start -->Administrative Tools -->Active Directory
Users and Computers), right-click the created user account and select Properties.
11. In the Select Groups dialog box, type Domain Admins and click OK.
Training, Teaching and Learning Materials (TTLM)
After you have created the Active Directory domain and the domain administrator account, you should add
all the nodes to the domain. This can be done as follows:
1. Log in to the first node you wish to add to the domain, right-click the My Computer icon, and click
Properties.
o In the Computer name field, specify a server hostname. This name will be used to uniquely
identify the given node among other nodes in the cluster. By default, you are offered to use
the hostname assigned to the node during the Windows Server 2003 installation. However, we
recommend that you change this hostname to something more descriptive (e.g.
CLUSTERNODE1).
o Select the Domain radio button and type the domain DNS name (you specified this name
during the Active Directory domain). In our example the domain DNS name should be set to
mycompany.local.
After providing the necessary information, your window may look like the following:
5. Click OK to close the displayed message welcoming you to the domain and then click OK once more to
close the Computer Name Changes window.