The database model is managed in T-SQL scripts. Adjustments to the model are made in SQL Server Management Studio and exported to files.
Steps to build the T-SQL create script:
- Run the
Db.ExportModelCreate.cmd
command- start the mssql-scripter
- start the SQL code formatter
- Manual editing of ModelCreate.sql
- remove the
CREATE DATABASE
andALTER DATABASE
statements from the top (up to theBuildAttributeQuery
function) - remove the
ALTER DATABASE
andSET READ_WRITE
statements from the bottom
- remove the
Steps to build the T-SQL drop script:
- Run the
Db.ExportModelDrop.cmd
command- start the mssql-scripter
- start the SQL code formatter
- Manual editing of ModelDrop.sql
- remove the
USE [PayrollEngine]
statements from the top - remove the
USE [Master]
andDROP DATABASE [PayrollEngine]
statements from the bottom
- remove the
Commands to import SQL script files into the database:
Db.ModelCreate.cmd
- create the databaseDb.ModelDrop.cmd
- drop the databaseDb.ModelUpdate.cmd
- update the database: first drop and then create
To support index on nullable fields, the SQL index requieres a filter condition. For example the range value on the lookup value:
CREATE UNIQUE NONCLUSTERED INDEX [IX_LookupValue.UniqueRangeValuePerLookup] ON [dbo].[LookupValue] (
[RangeValue] ASC,
[LookupId] ASC )
WHERE ([RangeValue] IS NOT NULL)
Please note: the condition of a filtered index is not visible in SSMS.
See also:
This also means that if you have a multi-column index across several columns, having a single-column index against the first column in the multi-column index is redundant and superfluous – the multi-column index can be used just as easily in queries only constraining that one, left-most column.
See also: