to cover The Four Rules of Database Deployments. Regardless of whether you decide to use MD3 or not, if you understand The Four Rules your database deployments will run much smoother.
MyIndex
, created on dbo.Example
with a fill_factor of 90, on column Foo
, with included_column Bux
. Here is the DDL:MD3.Indexes
), which looks very similar to the "sys" system tables (in this case sys.indexes
). Here's a screenshot that shows how to add an index to the HumanResources.Department table: MD3.CreateIndex
(which you can call instead of populating the MD3.Indexes
table) similar to the nearby graphic that is adding the index nciFoo
to dbo.Example
. MD3.CreateIndex
(and each column in the MD3.Indexes
table (see above screenshot) is a metadata property that we can declare for an index. These properties cover just about every option you can think of regarding an index. There are some properties missing...for instance, there is no option for filtered indexes because I've never really found a good use case in my career where I absolutely needed a filtered index. Since MD3 is open source you could always add this functionality if you needed it. Here are some other index properties that are missing and why:Index Property | Why it is missing? |
---|---|
WHERE <filter predicate> | filtered indexes. You can always add this yourself. |
IGNORE_DUP_KEY | I've never found a good use for this option. |
STATISTICS_NORECOMPUTE | I've never found a need for this. |
DROP_EXISTING ON|OFF | MD3.CreateIndex will smartly determine if this should be set to ON or OFF based on what is being asked. |
ONLINE = ON|OFF | MD3.CreateIndex will determine whether this option should be used or not for you, based on whether the index follows the rules for ONLINE index creation. Here is another case where MD3 is a huge help. |
So the question is...how does MD3 actually build the DDL under the covers and what makes it so much better than hand-crafted DDL?
MD3.Create
procedures (see the screenshot above). sp_rename
. This scenario occurs, for instance, when your DBA adds an emergency index to a table and you check in the same index structure, but you use your naming conventions. MD3.CreateIndex
(tsqlt unit tests available on request). Database State | Expected Result | Why? | Covers which of The Four Rules |
---|---|---|---|
dbo.Example table does not exist | FAILURE | This scenario will be caught during continuous integration testing and will never happen during a production deployment. (See [[Continuous Integration Testing with MD3]]) | None. |
index nciFoo does not exist | Index created | The index will be created with the declared properties. | 4 |
An index exists called dbaFoo with the same properties | Index renamed | The index will be renamed using sp_rename to nciFoo . This ensures that a duplicate index is not created with the same properties. | 2 |
nciFoo exists, but with different "properties" than what is declared | Index altered | When possible the index will be ALTERed. Otherwise the existing index will be dropped and the desired index will be created. In some cases, depending on what is being changed, an index cannot be ALTERed. | 3 |
nciFoo exists with identical properties | Silently continue | There is no work to do. | 1 |
You have just read "[[MD3 and The Four Rules]]" on davewentzel.com. If you found this useful please feel free to subscribe to the RSS feed.
Dave Wentzel CONTENT
md3 sql server data architecture