Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 19

DBA Skills:

What is a DBA – is typically responsible for administering a db and db server, as opposed to a developer who does
much of the development work for a database. Responsibility often include recoverability (backups and restores),
maintaining integrity, managing security, ensuring availability and maximizing performance

Writing Ad hoc SQl Queries


Applying Updates and patches
Updating antivirus
Migration from 2000 to 2005

Performance Tuning

Optimization
 Optimizing database with index and optimizing the index – adding indexes to frequently queried data will
significantly improve the performance of the queries that use the data. Clustered and non-clustered indexes.
 Viewing and updating Statistics – DBCC show_statistics; UPDATE Statistics
 Full Text catalogs and indexes
 Database Engine Tuning Advisor- recommend index to create, to drop, index views, analyze the effects of the
proposed changes, provide report summarizing the changes and the effects of the change
 Index maintenance – occasional search on a db to ensure that all created indexes are being used. Drop unused
index to eliminate needless overhead. As database are constantly be modified, splits occurs. The more page
splits an index experiences, the more fragemented it becomes. An index can experience logical fragmentation
(where pages are out of order) and extent fragmentation (where extents are out of order). Reorganize and
rebuild are used to defragment and index.. SELECT * from sys.dm_db_index_physical_stats
 Database Console Command (DBCC)
 Use of file groups
Disaster Recovery - the ability to recover system operations after a disaster (fire, flood, virus, accidental or purposeful
 Backups – an easy way to to verify the integrity is to run the DBCC CheckDB stmton the db after doing a tes
restore of the database.
 Log shipping – keeping a full copy of your db on another system. No auto fail over
 database snapshots – the state of the db at a point in time, it protect data from user error, safeguard data against
adm error, maintain historic data for report generation.
 Database mirroring – high avail, automatic failover, used to mirror database on separate servers. It uses a
Witness server for auto failover. For the witness server to support auto failover, the witness server must be in
synchronous-operation mode
Transfering data –
 BCP (Bulk copy program) utility bulk copies data btw SQL server 2005 and a data file, using the format
specified my the user
 Bulk Import and Export,
 Openrowset – used to connect to non-Microsoft server remote data source and access data from the data source
 Opendatasource – used to provide ad hoc connection information as part of a four-part object name without
using linked server name
 Replication – high avail; a set of technologies used to copy and distribute data among multiple users or
consumers. The users can be local or in a multiple remote locations connected via a LAN, a WAN, the internet.
it does not distribute entire db but part of the db eg table or view (called articles) and are distributed as part of
publication.
 Snapshot replication – replication of the data a moment of time. With snapshot replication, the entire
data set is replicated at the same time.
 Transaction replication – Replication that starts with a snapshot and keeps the subscribers up-todate by
using the transaction log
 Merge replication –used when multiple subscribers are also acting as publishers. The data is updated
from multiple sources.
Data modification and validation

Security

 Services –making sure that unneed services are not running – reduce the attack surface of the server
 Auditing – tracks what is occurring on a system. Triggers (DML, DDL) are used to audit database and database
schema activities
 Creating logins and database user with the appropriate permissions
 Securable such as tables, views, and stored procedures
 Setting permissions
 Encryption – protects data from accidental disclosure
 Password policy – setting check_policy on
 Server roles –
SysAdmin – allow access to anything and everything
ServerAdmin – can modify serverwide confi option and shut down the server
SecurityAdmin – can manage logins and login properties. Can GRANT, DENY and INVOKE permissions at
ServL
DBCreator – Create, alter, drop and restore any db
BulkAdmin – run Bulk Insert
ProcessAdmin – Can terminate processes running on SQL Server
SetupAdmin – can add and remove linked servers. Can execute some procedures
DiskAdmin - can manage disk files

Maintenance Task – management -> maintenance plan -> maintenance plan wizard.
 system monitoring
 Backing up database and transaction logs
 Reorganizing and rebuilding statistics
 Check database integrity
 Updating statistics
 Deleting old history logs
 SQL Server Profilier –
 Used to track down long running queries and stored procedures
 Identify poorly performing ad hoc quries
 Identify deadlocks and associated connections. Dead locks occurs when two different processes have a
lock on one resources but are trying to access a second resources, which is already locked by the other
process
 Monitor stored procedures
 Audit activities on sql server
 Monitor activities on a per user basis
 Collect data for turning.

SSIS – SQL Server Integration Services used to build data integration packages, including ELT packages.
SSAS – SQL Server Analysis Services includes tools and features for OLAP that are used to design, deploy and
maintain cubes
SSRS – SQL Server Reporting Services a server based reporting platform used to create and manage a wide variety of
reports, including paramterized report, report snapshot or more. Can be deployed to an IIS server so they are easily
accessible to users.
SD3+C - Secure by Design, Securew by Default, Secure in Deployment and Communicatis
SQL Server DBA : Common tasks and solutions

Welcome to the SQL Server DBA section of this site.

In this section, you will find a set of common tasks needed to be mastered and performed by any SQL Server DBA. The articles are basic level, and graphic
intensive, so you will need some network speed to read them.

I recommend that you print each article for better reading experience. Use landscape orientation on your printer.

The SQL Server Database system from Microsoft Corporation has gained popularity over the last years, and it is believed to be one of the few surviving
relational database systems in this marketplace (the others being Oracle and DB2 from IBM).
I tend to agree with that, and want to present to you a set of SQL Server DBA articles, which include:

 Adding users
 Backup and restore
 Import and export data
 Job scheduling

and much more...

So let's get on with it. Here are some SQL Server traing lessons for DBAs:

 Adding users in SQL Server is one of the most funtamental tasks you'll perform. This article describes in great detail the different steps you have to
take to establish a new user in SQL Server.
 Have you ever needed moving the database from one location to another? In SQL Server, you will need functionality to detach and attach your
database in order to move it from one location to another. Here you will find a thorough description of what you'll need to do.
 As a DBA, you will very likely need to move bulks of data from one database to another, or make a copy of your data. This article provides a step-
by-step tutorial on Import and Export in SQL Server
 Today's database systems need mechanisms to increase performance. One of the most important things you can do, is adding SQL Server indexes
 Scheduling jobs is a very useful functionality of the SQL Server database. There are several uses of this feature. Read more in this article on SQL
Server jobs
 Preparing a maintenance plan is an important task, but SQL Server provides you with a wisard for such a plan. Read this tutorial on how to set up a
SQL Server Maintenance Plan
 Every database needs a backup copy. Hopefully, you will never need it, but all practice has learnt us that a backup can come in very handy. Read this
tutorial on how to produce a SQL Server backup
 When disaster happens, you have of course a disaster plan and a backup of the database?. If so, it is easy to perform a SQL Server Restore Database
operation.
 Sooner or later, you will most likely have to search for performance bottlenecks, or perform other monitoring tasks. This article is a simple tutorial on
how to use SQL Server Profiler
 If your database should go down, you need to bring it back to as current state as possible. In case of a system failure, the SQL Server Transaction Log
will prove invaluable.

Adding users in SQL Server

SQL Server provides an effective method for adding users in SQL Server and for managing data and information so that it can easily be stored and
retrieved from the underlying files in order to provide the functionality it is designed for.

Once the database is designed, configured and implemented, it is critical that you start adding users in SQL Server so that people needing access to the data or
specific bits of data be granted access to what they need to be able to access.

This is increasingly important as the need for more secure practices, guidelines and policies becomes a greater force in the workplace. Security has become
more prevalent in the day-to-day operations of practically every organization in the world.

So how can SQL Server and its’ built in security allow for a more secure organization and help to protect the data that we are trying to guard?

Working with SQL Server and the security it has within it is a critical component of database administration. Adding users in SQL Server is an important task.
When adding users in SQL Server, it provides three methods of authenticating users within the database that can be implemented in order to control how users
are granted access to the database.

These three methods are windows authentication, SQL Server authentication and mixed-mode authentication.

Windows authentication performs a check of the user credentials with a network validation to ensure that the user has access to the resource.

SQL Server authentication requires a valid SQL Server login name and password combination to validate the user access against the database before granting
access to the resources on the server.

Mixed mode security will allow the user to connect to the database via a valid Windows account or through a valid SQL Server login. The type of security you
implement depends on the type of security architecture you decide is best for your specific needs on the server and the network.

In order to configure security in SQL Server, the administrator may have to use not only tools within SQL Server but must also work with network accounts in
order to grant access and adding users in SQL Server correctly.

In order to view the logins that are used and defined within SQL Server using Enterprise Manager, select the Security node within Enterprise Manager. The
Logins node within Security will allow you to view the logins defined within that database.

The illustration below shows the screen and the information that it will provide anyone who looks at it.

The first column is the name of the login as it is known by the database. The type column is next and depicts what type of login it happens to be within the
database.

The following column tells whether or not the login has access to the server. This is the Server Access column.

The next two columns deal with default settings for the user within the server. These settings deal with the database that serves as the default database for that
login and the default language that is associated with that account.

In order to edit a login in SQL Server double-click on the login or right click and select Properties. Doing so will bring up the following dialog:
The General tab deals with the type of authentication to use for the login as well as setting the default database and language for that login.

If Windows authentication is chosen, a domain must be selected and then the security access should be either granted or denied to the login.

If SQL Server authentication is chosen, the password should be entered. Click OK to save any changes. The dialog also contains a tab to allow the
administrator to define the server roles for the login (Server Roles).

The following illustration shows this tab:


The server roles can be selected and then click OK to save the changes. Each role has specific rights within the server and in order to understand what the login
should be associated with, the roles should be understood by those assigning them.

The final tab on the dialog is the Database Access tab. The following illustration shows this tab:
This tab will allow the administrator to select each database within the SQL Server and specify the database roles within that database.

These roles can grant and/or deny various capabilities within the databases for that particular login. Some examples of these roles include a data writer role,
which will allow the user to update and insert data into the database and a data reader roles that allows the user to query the database in order to view the data.

Users can also be added to individual databases by expanding the database in question and then selecting the Users node. The following illustration shows this
screen:
In order to access the properties for a particular user, double click that user or right click and select Properties from the popup menu. This will bring up the
following dialog in order to manage the permissions assigned to that particular user account.
The Permissions button will bring up the dialog to allow the administrator to grant or allow access to specific objects within the database. The following dialog
shows this portion of the process:

By selecting and deselecting specific options within this dialog, the administrator can assign and deny access to certain objects within the database.

Different object types will have different operations that can be executed against them as can be seen in the illustration above.

For example, tables and views can have Select, Insert, Update, Delete and others while stored procedures do not have these operations.

The Columns button applies to views and tables and can be used to control what columns that user has access to within the database.

This level of control can help to make a database extremely secure, but can cause issues for those who are not familiar with the security that has been
architected for a particular database or a server. Once the changes have been made to the user, they can be saved by clicking the Apply button.

Hopefully, you now have a better understanding of how to adding users in SQL Server and how to work with security within SQL Server, as well as setting up a
secure database environment in order to protect your data and your information that can prove to be vital to the success of your business.

Moving the database : SQL Server detach and attach


If you need moving the database to another location, the attach and detach functionality is indispensable.

As many of you may or may not know, SQL Server is a database management system used to store data and objects
needed to work with that data.

It is one of many products on the market designed for this purpose. SQL Server works by allowing the user to specify a
location on the physical drives accessible by the server and providing the engine needed to store, retrieve, organize and
utilize the data and objects within the database.

The database is stored in files on hard drives that are accessed in order to gain access to the contents of the database.
The files associated with a database have a default location, but upon database creation, they can be configured to go to
another location.
This allows for data to be better configured and organized across hard drives that may have limited space available for
data storage. What happens however, when a file needs to be incorporated into the database management system from
an external source?

This is where the concept of moving the database by attaching and detaching comes into play.

When a database is used and managed by SQL Server, the data files on the hard drives associated with that database are
locked to use by any other application.

If you try to access that file, a message will alert you to the fact that the file is being used by another application and
you cannot access it. This makes the possibility of moving a database from one location to another or copying the
database for use by another agency out of the question.

For example, if you were traveling to another location to work on an application and you had to work from a machine
that did not have access to that database, you could take a copy of the database to use to work with.

This is where the ability to attach and detach a database will come into play. You can detach a database in order to
remove it from the control of SQL Server and enable the files to be accessed by external methods or applications.

This is where the concept of detaching a database can be used. By detaching a database it can be copied and moved to
another location without interference from the SQL Server managing that database.

Detaching a database in Enterprise Manager can be accomplished by the following:

1. Right-click on the database in question. This will bring up menu options shown below:

After brining up the menu options, go to the Detach Database option under the All Tasks menu option as illustrated
below:
Select the Detach Database option to begin detaching the database from the database management system. After
selecting the Detach Database option the following screen will appear to confirm the detach operation:

This screen informs the user of the number of active connections to the database.

This can be helpful so that users of the database can be informed that the database they are using is getting ready to
become unavailable so that they can save the work that they are working on help you determine a better schedule for
the when the detachment operation can occur.

The screen also shows whether or not the database is being used in replication and whether the database is ready to be
detached.

If you would like to update the statistics for the database prior to detaching it, the option can be selected.

To proceed with the detachment of the database click the OK button. To cancel the operation, click the Cancel button.
The detaching of the database is confirmed with the following dialog box:
The database can also be detached from the database management system using Query Analyzer and the Transact-SQL
language. To do so, open a session in Query Analyzer and enter the sp_detach_db command. The syntax for the
command is as follows:

sp_detach_db 'dbname' ,'skipchecks' ]

The dbname is the database name that is used by SQL Server to access the database. The skipchecks parameter is
optional and instructs the server to either update the statistics for the database or not.

For example, if we wanted to detach the Northwind database that comes with SQL Server the following statement
would accomplish that feat:

sp_detach_db 'Northwind’

Once the database is detached you can start moving the database to another location or transport it to the location where
it is needed and can be attached to the server in order to access the database once again in SQL Server.

To access the database once again via the database management system, it must be reattached to the database.

In order to perform the attachment of a database via Enterprise Manager, right click on the databases tab in Enterprise
Manager, select the All Tasks option and then the Attach Database option from the menu.

The following illustration shows the options needed to perform the operation:
By selecting the Attach Database command the following dialog box is shown to continue the operation.

The first parameter that must be input is the mdf file for the database that needs to be attached. The command button
shown to the left will bring up the file browser to allow the standard file selection methods to be employed.

After the file is selected, it can be verified using the Verify command button. A name is given to attach the database as
and also to specify the owner of the database.

The OK command button will finalize the attach operation and shows the following dialog box to alert the user that the
operation was successful.

Clicking the cancel button can be used to cancel the operation from continuing.

The database can also be attached by opening up a Query Analyzer session and using Transact-SQL to perform the
operation. The syntax of the attach command is as follows:

sp_attach_db 'dbname' ,'filename_n'

The dbname is the database name that is used by SQL Server to access the database. The filename_n indicates that
there can be more than one file associated with the database.

There can be filename1 through filename16 files associated with the database. Once it is attached the database can be
accessed by SQL Server again.

For example, in order to attach the Northwind database we detached in the previous example, the following statement
can be used:

sp_attach_db 'Northwind' ,'c:\\\\\\\\\\\\\\\\somelocation\\\\\\\\\\\\\\\\northwind.mdf',


‘c:\\\\\\\\\\\\\\\\location\\\\\\\\\\\\\\\\northwind.log’
Many people may be asking themselves why they may need this ability, but for those of us who have had to send a
database somewhere else for it to be used, it is a blessing that it exists.

I hope that moving the database from one location to another seems like a doable task after reading this.

Return from Moving the Database to SQL Server DBA

Import and export in SQL Server


SQL Server: The Advantage of the Import and Export in SQL Server Tools

While SQL Server can be used to house the data that your company maintains on a daily basis and offers a way to
effectively and efficiently manage the objects and data within that database, there are often times when getting initial
data into a database can be a hassle.

However, not only does SQL Server manage the data and objects contained within the database, it has tools that can be
used to get data into tables quickly from a variety of external sources.

SQL Server provides to those who use it, the ability to import and export in SQL Server to many different formats. This
can be extremely useful for someone wanting to quickly get data into the database or out of the database for any reason.

For example, an agency that sells mailing lists could easily export the data from a SQL Server database to a format that
could be burned onto a CD and delivered to the customer very quickly.

On the other hand, the same company could buy a mailing list file from another agency or third party and import the
data into their database and save the time of having to key the data into the database or an application.

So how can the import and export in SQL Server data tools that are provided by SQL Server be used to get data into a
database quickly?

In order to use the import and export in SQL Server Data functions, right click on the server in Enterprise Manager that
you would like to use as a basis for the Import or Export.

Then select the Import Data or Export Data menu option from the All Tasks selection as shown in the image below:

The interface for Import Data and Export Data is the same, each presents the user with different options for the
destination and source for the data involved in the operation.
Regardless of what operation you wish to conduct when transferring the data, an import or an export, each option will
provide you with the functionality you need.

For clarification, regardless of whether you want to import or export data, the options are provided that will allow an
import or an export to occur once the operation is initiated. Once the selection is made, the following window appears:

Select the Next button to continue with the Import/Export Wizard. This will bring up the following screen:
This screen will allow the user to select the data source, which is a drop down list of all the types of data that can be
used with the import/export.

These include many different formats, not just SQL Server data. The source type can be SQL Server, Access, Oracle or
any other data store that can be accessed via ODBC as well. After the data source type is selected, the user is then
presented with the specifications needed to specify the location of the source data.

Each option comes with different parameters needed to locate, connect and open the data source. Once the data source
is configured, click next which will allow the selection of the destination for the data.

In most instances you will be required to input information that will allow the database to verify who you are and
securely control access to that particular repository of data. Each type of data has differing parameters and must be
experimented with in order to learn the full functionality of the import/export capabilities of SQL Server and the tools it
offers. The following graphic illustrates this screen:

This screen is used the same way as the previous one used to input the source of the information for the import and
export in SQL Server.

It functions the exact same way the source screen works except that it represents the connection used to access the
destination database. If the user wants to go back to the source screen, click the back button. Clicking next will bring up
the next screen.

This will allow the user to select the type of objects that they want to move.
The user can select to move tables, use a query to specify the data or move data and objects between databases.

Selecting the copy tables option will allow the user to select tables to move in their entirety to the destination. The use
of the query option will allow the user to enter a query to specify the data that needs be moved. This can be used to
limit the fields or the amount of data being moved.

The transfer objects option will allow the selection of objects to be moved between SQL Server databases.

All of these options are very important when trying to determine how to import and export data in SQL Server. After
the choice is made, the user can click next to move on to the next screen, which is shown below.
To continue with the import and export in SQL Server operation, this screen will allow the selection of the source and
destination objects and the data transformations that need to occur in order to move the data to the correct location.

These transformations can be a straight copy or they can be the result of data manipulation via scripts in order to make
the data fit the format you need or transform the data into other elements. Once this is complete, click the Next button,
which will bring up the following screen.

After this information is input, our import/export operation is almost ready to run on the server to complete the
movement of the data.
This will allow the user to run the import/export now or save the configured import/export as a DTS package to be run
later or saved on the server to be run as needed.

You may be asking yourself why this utility to import and export in SQL Server is so advantageous, imagine if you had
to use data entry tasks in order to manually enter a list of thousands of records of data.

How much time could be saved if the data could be loaded via a file in the import/export data utility?

Experience has proven to me that this tool can prove to be invaluable if the developer or database administrator
becomes familiar with the power that it provides. It has saved me numerous hours on projects and has been used
exclusively for data transformation tasks that would not have been possible without a tool such as this.

Moving data using the import and export in SQL Server can prove very useful along with the rest of the DTS features
in SQL Server.

You might also like