Looking at index fragmentation, can give us a very specific idea of a tinylittle piece that we want to keep an eye on and fix and maintain in ourdatabase, but what about the larger idea of the database itself and theconsistency and integrity of the database?Well we can use some of those reports to get some very useful information.If I right-click any of my databases I can drop into my reports, my standard reports,and start off with something very simple and straightforward like the disk usage idea.How much space is this taking up?Getting this little pie chart that will tell me how much of it is data thepurple stuff, how much of it is index, how much of it is unallocated and justbeing held back for new rows and new information.

And that's useful, but won't really guide you in any particular direction to doing anything.However, some of the other reports can be a bit more useful that way.We can drop into disk usage by top tables, allowing you to quickly scan which ofyour tables are taking up,both of them have a space and have the most rows in them, not necessarily the same thing.We can drop into our reports, and one of the ones that I like is the DiskUsage by Partition.Now we don't cover partitioning in this course.Partitioning is the ability to take large tables and actually split them acrossmultiple physical file structures.

It's not something we can do with SQL Server Standard edition.It's only actually available in the Enterprise editions.But the report nonetheless gives us some interesting stuff to look at.Because it will show us all our tables and allow us to scan things like ourindexes and how much space those take up.So here at the DimCustomer table 18,000 rows, 9,000 K, and I can scan theindexes as well, but seems to show some consistency.I've got 18,000 rows in them, but it shows me how space the indexes are taking up.

Dropping back in to the Reports we have things like view all our transactions.I haven't executed anything against this database for quite a while so there isnothing that's been run.But we would have that if we wanted.We've got user statistics, schema changes, the index usage and physicalstatistics we saw in the previous movie.I also have this one, Database Consistency History.Now the first time you run it, you're likely to see no messages at all.Because what it's telling you is this.It's a history of executions of DBCC CHECKDB.

Well what the devil does that mean?DBCC CHECKDB is a command that you can run if you're in the SysAdmin role andit does internal consistency checks on the database.Let me show you how you do it.Open up a new query window, making sure that AdventureWorksDW is selected orwhatever database that I want to run this on, and I simply type DBCC CHECKDB. Execute.Depending on the site of your database it may take a while to do it.But when it comes back, it's going to run a whole bunch of internal checks onyour tables and some of the background objects that support your tables.

And hopefully you will end up with CHECKDB found 0 allocation errors and 0consistency errors in the database.Even if you're doing backups regularly, even if you're taking a look at yourindexes and defragmenting those, you should be running this DBCC CHECKDB on afairly regular basis, at least weekly.Possibly more often if you've got a very volatile database.Again like with your indexes this should be part of your enterprise levelmaintenance plan idea.But the nice thing about it is every time it's run, it is then stored in the log, and if I run my report again on the Database Consistency History, I shouldexpect to see 2 instance of this and how long they took.

Now obviously we're starting to build very complex structures here.And a real deep discussion on what we should be doing for database monitoringand optimization is beyond the scope of this course, but there's an immense amount of material, both inBooks Online and on the web, that you'll probably want to take a look at as youget deeper into your databases.

Resume Transcript Auto-Scroll

Author

Released

12/15/2010

In SQL Server 2008 Essential Training, Simon Allardice explores all the major features of SQL Server 2008 R2, beginning with core concepts: installing, planning, and building a first database. Explore how Transact-SQL is used to retrieve, update, and insert information, and gain insight into how to effectively administer databases. The course also covers features outside SQL Server's database engine, including technologies that have grown up around it: SQL Server Reporting Services and Integration Services. Exercise files are included with the course.

Topics include:

Using T-SQL (Transact-SQL)

Managing databases with SQL Server Management Studio

Understanding database normalization

Using SELECT statements

Building indexes

Monitoring database size and integrity

Backing up and restoring databases

Creating functions and stored procedures

Managing database permissions

Creating and formatting reports

Adding charts to reports

Creating and executing a simple SSIS package

Skill Level Beginner

6h 54m

Duration

2,095,816

Views

Show MoreShow Less

Q: I'm having problems installing the free Express R2 version of SQL Server on Windows XP. I tried 64-bit and 32-bit versions. In the videos, the author installs from a DVD. Do I need to do the same?

A: While the author installs from a DVD, it's not strictly necessary. There certainly shouldn't be a problem installing the Express edition from a regular download. That's the way it's intended to be installed.

If you're using Windows XP, the only officially supported version is the 32-bit version. However, you do need to make sure that your Windows XP install is completely up-to-date and patched, with XP Service Pack 3 installed. (See http://msdn.microsoft.com/en-us/library/ms143506.aspx#Express32 for formal requirements.)

It's not unusual for the install process to take a while, and with older operating systems like XP, you'll often have to back it out and try again, as usually there's a bunch of prerequisites that need to be installed. (Like the .NET Framework 3.5 SP1, the correct version of Windows Installer, etc.)

Q: The link to the installer for the AdventureWorks sample database, as shown in the Chapter 2 movie "Installing sample databases," no longer works. Where can I find the installer?

A: Microsoft has reorganized its site. The sample files are still there, but they're a bit harder to find. To install them:

1) Visit http://msftdbprodsamples.codeplex.com/.2) Click the link to "SQL Server 2008 R2 OLTP."3) Click the AdventureWOkrs2008R2 Data File link and agree to the conditions to download the MDF file.4) Move the MDF file to your SQL Server Directory, usually located at C:\Program Files\Microsfot SQL Server\MSSQL 10_50.MSSQLSERVER\MSSQL\DATA.5) Open the SQL Sever Management Studio and connect to your instance using an account with administrative privileges.6) Attach the sample database by right-clicking the Databases folder in the Object Explorer and choosing Attach from the pop-up menu.7) Click the Add button in the next menu and navigate to the MDF file in the Locate Database Files window that appears. Select it and click OK.8) Remove the reference to the log file in the "AdventureWorks2008R2" database details: pane by selecting the Log entry and clicking removing.*9) Click OK to return to SQL Server Management Studio and complete the attachment process.

*MDF files are the "data" files for SQL Server databases. They often come along with LOG files (ldf files). This one didn't so we need to REMOVE the reference to the non-existent log file. Select the second row in the lower section (it should say File Type: Log and Message: Not Found) and click the REMOVE button.

For an illustrated version of these instructions (with screenshots), click here for a PDF version.