Join Simon Allardice for an in-depth discussion in this video Monitoring database size and integrity, part of SQL Server 2008 Essential Training.
- View Offline
- Exercise Files
Looking at index fragmentation, can give us a very specific idea of a tiny little piece that we want to keep an eye on and fix and maintain in our database, but what about the larger idea of the database itself and the consistency 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 the purple stuff, how much of it is index, how much of it is unallocated and just being 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 of your 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 Disk Usage by Partition. Now we don't cover partitioning in this course. Partitioning is the ability to take large tables and actually split them across multiple 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 our indexes and how much space those take up. So here at the DimCustomer table 18,000 rows, 9,000 K, and I can scan the indexes 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 is nothing that's been run. But we would have that if we wanted. We've got user statistics, schema changes, the index usage and physical statistics 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 and it 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 or whatever 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 on your tables and some of the background objects that support your tables.
And hopefully you will end up with CHECKDB found 0 allocation errors and 0 consistency errors in the database. Even if you're doing backups regularly, even if you're taking a look at your indexes and defragmenting those, you should be running this DBCC CHECKDB on a fairly 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 level maintenance 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 should expect 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 monitoring and optimization is beyond the scope of this course, but there's an immense amount of material, both in Books Online and on the web, that you'll probably want to take a look at as you get deeper into your databases.
- 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
1. Getting Started
2. Installing SQL Server 2008 R2
3. Tools and System Databases
SQL Server system databases2m 22s
4. Creating Databases
5. Importing Existing Data
6. Retrieving Data with SQL
7. Inserting and Updating Data
8. SQL Functions
9. Stored Procedures and Transactions
10. Core Administration Tasks
11. Backing Up and Restoring
12. Security Features
13. Reporting Services
14. Integration Services
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.