34
Databases Databases Lesson 5

Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Embed Size (px)

Citation preview

Page 1: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

DatabasesDatabasesLesson 5

Page 2: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Skills MatrixSkills Matrix

Page 3: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Using SQL ServerUsing SQL Server• You can use SQL Server to perform

transaction processing, store and analyze data, and prepare reports.

• The SQL Server family of products and technologies meets the data storage needs of online transaction processing (OLTP) and online analytical processing (OLAP) environments. – OLTP specializes in getting the data into

the database, while OLAP focuses on getting the information out of the database.

Page 4: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

The SQL Server Relational Database The SQL Server Relational Database Management System (RDBMS)Management System (RDBMS)• Manages data storage for transactions and

analysis.• Stores data in a wide array of data types,

including text, numeric, XML, and large objects (CLOBS, character large objects, and BLOBS, binary large objects).

• Responds to requests from client applications.

• Uses Transact-SQL, XML, or other SQL commands to send requests between the client application and SQL Server.

Page 5: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

RDBMS ComponentsRDBMS Components

• Maintains the relationships among data in a database.

• Ensures that data are stored correctly and the rules defining the relationships among data are not violated.

• Recovers data to a point of known consistency in the event of an infrastructure failure.

Page 6: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Planning your DatabasePlanning your Database

• SQL Server uses two types of files to store your database information: – One or more database files.– One or more transaction log files.

Page 7: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase Files

• Everything in the Model database shows up in your newly created database.

• Once the copy of the database has been made, it expands to the requested size.

• When you create a database in SQL Server, you must specify at least one file to store the data and hold your system tables and another file to hold the transaction log.

Page 8: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase Files

• Databases can comprise up to three file types.

• Primary data files have a default extension of .mdf.

• If you create a database that spans multiple data files, then secondary data files are used, which have a default filename extension of .ndf.

• The transaction log is stored in one or more files, each with a default .ldf extension.

Page 9: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase Files

Page 10: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase FilesYou should remember several important facts

about your data and log files:• Create the data and log files on a storage

area network (SAN), iSCSI-based network, or locally attached drive.

• You may have but one database per data file although a single database can span multiple data files.

• Transaction logs must reside in their own file; they can also span multiple log files; and should reside on their own, dedicated spindle.

Page 11: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase Files

• SQL Server fills the database files in a filegroup proportionally.

• Transaction log files are not filled proportionally; instead, each fills to capacity before continuing to the next log file.

• When you create a database and don’t specify a transaction log size, the transaction log will be resized to 25 percent of the size of your data file request.

Page 12: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database FilesDatabase Files

• Place your transaction logs on separate physical hard drives (also known as spindles).

• If you have selected the full recovery model, you may recover your data up to the moment of failure in the event of data loss.

Page 13: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

FilegroupsFilegroups• You can logically group database files into a

filegroup. • Using filegroups, you can explicitly place

database objects into a particular set of database files.

• Another advantage of filegroups is the ability to back up only a single filegroup at a time.

• Yet another advantage includes the ability to mark the filegroup and all data in the files that are part of it as either read-only or read-write.

Page 14: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

FilegroupsFilegroups

• There are really only two disadvantages to using filegroups. – The administrative effort involved in

keeping track of the files in the filegroup and the database objects that are placed in them.

– If you are working with a smaller database and have RAID-5 implemented, you may not be improving performance.

Page 15: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Database File PlacementDatabase File Placement• Should be placed on some form of RAID.• RAID is short for Redundant Array of

Independent Disks. • RAID exists in many configurations.

Microsoft Server editions support:– RAID 0 (striping)– RAID 1 (mirroring)– RAID 5 (parity)– RAID-10 (sometimes referred to as RAID

1+0)

Page 16: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

ExtentsExtents• An extent is a block of eight pages totaling 64

KB in size. • Because the extent is the basic unit of

allocation for tables and indexes, and all objects are saved in a table of some kind, all objects are stored in extents.

• SQL Server has two types of extents:– Uniform: In uniform extents, all eight pages

are used by the same object.– Mixed: Mixed extents are used by objects that

are too small to take up eight pages, so more than one object can be stored in the extent.

Page 17: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

PagesPages

• At the most fundamental level, SQL Server stores everything on an 8 KB page.

• The page becomes the one common denominator for all objects in SQL Server. Many types of pages exist, but every page has some factors in common.

• Pages are always 8 KB in size and always have a header, leaving about 8,060 bytes of usable space on every page.

Page 18: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

PagesPages

• SQL Server has eight primary types of pages:– Data pages– Index pages– Text/Image pages– Global Allocation Map pages– Index Allocation Map pages– Page Free Space pages– Bulk Changed Map pages– Differential Changed Map pages

Page 19: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Creating a DatabaseCreating a Database

• You can create a database in SQL Server in two ways:– CREATE DATABASE statement in a

Transact-SQL (T-SQL) query.– Use the graphical tools in

Management Studio.

Page 20: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports
Page 21: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Gathering Information About Your Gathering Information About Your DatabaseDatabase

• Using SQL Server Management Studio, you can gather a wealth of information about your database. – This includes the size of the database, its

current capacity, any options currently set, and so on.

• When you select a database in Management Studio, right-click and choose Reports. – You see a variety of reports that you can

use to gather information.

Page 22: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Gathering Information About Your Gathering Information About Your DatabaseDatabase

• You can also use system stored procedures to gather information about your database. The sp_helpdb stored procedure used by itself gives you information about all databases in your SQL Server. You can gather information about a particular database by using the database name as a parameter.

Page 23: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Setting Database OptionsSetting Database Options• Database options allow you to specify how

your database behaves in given situations. • You can view and modify database options

using Management Studio or the ALTER DATABASE statement.

• Start Management Studio and move down through the console tree until you see your database. Right-click <your database> and choose Properties. From the Database Properties sheet, click the Options page.

Page 24: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Setting Database OptionsSetting Database Options

• Collation• Recovery Model• Compatibility Level

Page 25: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Recovery ModelRecovery Model

• Simple• Bulk-logged• Full

Page 26: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports
Page 27: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Other Options: Automatic SettingOther Options: Automatic Setting

• Auto Close• Auto Create Statistics• Auto Shrink• Auto Update Statistics• Auto Update Statistics

Asynchronously

Page 28: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

SummarySummary

• The SQL Server data storage structure involves more than just a file or a collection of files.

• This internal architecture exists for one purpose alone: to input, store and retrieve your data as quickly and efficiently as possible.

• This lesson covered many aspects of data storage.

Page 29: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

SummarySummary

• Databases, and the files they are made of, include the following:– The primary data file has an .mdf

extension used to hold data.– Secondary data files have an .ndf

extension and are used to hold data.– Log files have an .ldf extension and are

used to store transactions before they are written to the database so that the database can be recovered in the event of an emergency.

Page 30: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

SummarySummary

• You were introduced to the various RAID levels you can use for fault tolerance and performance:– Use RAID-1 primarily for transaction logs.– RAID-5 should be used for your data files,

if required. RAID-5 does slow throughput.– RAID-10 (also called RAID 1+0) can be

used for either data or logs, but costs more and is available only as a third-party hardware solution.

Page 31: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

SummarySummary

• You learned about pages and extents which allow SQL server to store or retrieve just 64 kilibytes at a time no matter how large the data file using an indexed sequential access method.

Page 32: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

SummarySummary

• You learned in Lesson 4 how to estimate the size of a data file before creating it.

• You learned how to create databases using Management Studio and Transact-SQL and set database options to meet your specific needs.

• You learned about the recovery models, what they do, and when to use each one.

Page 33: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Summary for Certification ExaminationSummary for Certification Examination

• Know how to create databases. – SQL Server focuses on storing and

retrieving data in databases.

• Understand your files. – Know how big to make your files and

where those files should be placed.

• Know your recovery models. – Know how each recovery model

functions and what they allow you to restore.

Page 34: Databases Lesson 5. Skills Matrix Using SQL Server You can use SQL Server to perform transaction processing, store and analyze data, and prepare reports

Summary for Certification ExaminationSummary for Certification Examination

• Know how filegroups let you backup and restore just portions of your database; that file groups can be distributed to different servers in your farm; and that filegroups allow you to place different portions of your database on different spindles.

• Know how to set database options using sp_configure.