Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 76831 Viewers
80 Video lessons · 130955 Viewers
52 Video lessons · 64841 Viewers
59 Video lessons · 50664 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.