Commit c18576f2 authored by dwentzel's avatar dwentzel

updated:

	AdventureWorks2012 samples
	some bugs in CreateIndex and PK that I forgot to previously merge
	added LICENSE.txt
parent 85ea9115
......@@ -40,6 +40,7 @@ BEGIN
AND sic.column_id = sc.column_id
WHERE st.object_id = OBJECT_ID(@FullName)
AND si.name = @IdxName
AND sic.is_included_column = 0
ORDER BY sic.key_ordinal
FOR XML PATH(''))
......
......@@ -74,6 +74,8 @@ BEGIN
SELECT @IncludedColumns = COALESCE (@IncludedColumns, '')
SELECT @IncludedColumns = REPLACE(@IncludedColumns,' ','')
SELECT @DataCompressionType = ISNULL(@DataCompressionType, 'ROW');
SELECT @DataCompressionType = COALESCE(@DataCompressionType, 'NONE') ;
SELECT @DataCompressionType = CASE WHEN convert(varchar(200),SERVERPROPERTY ('edition')) LIKE 'Enterprise%' THEN @DataCompressionType ELSE 'NONE' END;
IF (@DataCompressionType NOT IN ('ROW', 'PAGE', 'NONE' ))
......@@ -247,6 +249,12 @@ BEGIN
END
END
--ONLINE only works on Enterprise Edition
IF (@IsOnline = 1 AND convert(varchar(200),SERVERPROPERTY ('edition')) NOT LIKE 'Enterprise%')
BEGIN
SELECT @IsOnline = 0
END
--------------------------------------------------------------------------
--Check for clustered index on the table, and clustered index change,
......@@ -407,7 +415,7 @@ BEGIN
SELECT @SQL = ''
SELECT @SQL = @SQL + ' CREATE ' + CASE WHEN @IsUnique = 1 THEN 'UNIQUE ' ELSE '' END
SELECT @SQL = @SQL + 'SET QUOTED_IDENTIFIER ON; CREATE ' + CASE WHEN @IsUnique = 1 THEN 'UNIQUE ' ELSE '' END
SELECT @SQL = @SQL + CASE WHEN @IsClustered = 1 THEN ' CLUSTERED ' ELSE ' NONCLUSTERED ' END + ' INDEX ' + @IndexName+ ' ON ' + @SchemaName + '.'
SELECT @SQL = @SQL + @TableName + ' (' + REPLACE(@IndexKeyColumns,'(-)',' DESC') + ')'
SELECT @SQL = @SQL + CASE WHEN @IncludedColumns <> '' THEN ' INCLUDE (' + @IncludedColumns + ')' ELSE '' END
......
......@@ -41,6 +41,9 @@ BEGIN
SELECT @PrimaryKeyName = MD3.f_RemoveBrackets (@PrimaryKeyName);
SELECT @FileGroupOrPartition = MD3.f_RemoveBrackets (@FileGroupOrPartition);
SELECT @KeyColumns = MD3.f_RemoveBrackets (@KeyColumns);
--Set the compression option
SELECT @DataCompressionType = COALESCE(@DataCompressionType, 'NONE') ;
SELECT @DataCompressionType = CASE WHEN convert(varchar(200),SERVERPROPERTY ('edition')) LIKE 'Enterprise%' THEN @DataCompressionType ELSE 'NONE' END;
-- if requested to drop the index, do that (if it exists)
IF (@DropPK = 1)
......@@ -166,7 +169,7 @@ BEGIN
-- string together the ALTER SQL
SELECT @SQL = ''
SELECT @SQL = @SQL + 'ALTER TABLE ' + @SchemaName + '.' + @TableName + ' ADD CONSTRAINT ' + @PrimaryKeyName + ' PRIMARY KEY'
SELECT @SQL = @SQL + 'SET QUOTED_IDENTIFIER ON; ALTER TABLE ' + @SchemaName + '.' + @TableName + ' ADD CONSTRAINT ' + @PrimaryKeyName + ' PRIMARY KEY'
SELECT @SQL = @SQL + CASE WHEN @IsClustered = 1 THEN ' CLUSTERED' ELSE ' NONCLUSTERED' END
SELECT @SQL = @SQL + ' (' + REPLACE(@KeyColumns,'(-)',' DESC') + ')'
SELECT @SQL = @SQL + CASE WHEN @FillFactor > 0 THEN (' WITH(FILLFACTOR = ' + CAST(@FillFactor AS VARCHAR(3)) +',')
......
......@@ -9,7 +9,8 @@ AS
BEGIN
SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON
/*
Runs all Indexes found in MD3.Indexes
......
......@@ -9,7 +9,8 @@ AS
BEGIN
SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON
/*
Runs all PK Constraints found in MD3.PrimaryKeys
......
The MIT License (MIT)
Copyright (c) 2014 David Wentzel LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment