340 likes | 351 Views
Learn about SQL Server's relational database management system (RDBMS) and its components, database files, transaction logs, filegroups, and file placement on RAID.
E N D
Databases Lesson 5
Using 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.
The SQL Server Relational Database 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.
RDBMS 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.
Planning 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.
Database 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.
Database 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.
Database Files You 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.
Database 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.
Database 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.
Filegroups • 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.
Filegroups • 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.
Database 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)
Extents • 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.
Pages • 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.
Pages • 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
Creating 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.
Gathering Information About Your Database • 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.
Gathering Information About Your Database • 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.
Setting 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.
Setting Database Options • Collation • Recovery Model • Compatibility Level
Recovery Model • Simple • Bulk-logged • Full
Other Options: Automatic Setting • Auto Close • Auto Create Statistics • Auto Shrink • Auto Update Statistics • Auto Update Statistics Asynchronously
Summary • 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.
Summary • 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.
Summary • 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.
Summary • 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.
Summary • 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.
Summary 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.
Summary 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.