@@ -100,24 +100,24 @@ public String getReorderedScript(boolean isHtml)
100100 patterns .add (new SqlPattern (getRegExWithPrefix ("CREATE TABLE " ), Type .Table , Operation .Other ));
101101
102102 // Specific sp_rename pattern for table rename
103- patterns .add (new SqlPattern ("(EXEC(UTE)? )?sp_rename (@objname\\ s*=\\ s*)?'" + TABLE_NAME_REGEX + "',\\ s*'" + TABLE_NAME2_REGEX + "'" + STATEMENT_ENDING_REGEX , Type .Table , Operation .RenameTable ));
103+ patterns .add (new SqlPattern ("(EXEC(UTE)? )?sp_rename (@objname\\ s*=\\ s*)?'" + TABLE_NAME_REGEX + "'\\ s* ,\\ s*'" + TABLE_NAME2_REGEX + "'" + STATEMENT_ENDING_REGEX , Type .Table , Operation .RenameTable ));
104104
105105 // All other sp_renames
106106 patterns .add (new SqlPattern ("(EXEC(UTE)? )?sp_rename (@objname\\ s*=\\ s*)?'" + TABLE_NAME_REGEX + ".*?'.+?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
107- patterns .add (new SqlPattern ("EXEC(UTE)? core\\ .fn_dropifexists\\ s*'(?<table>\\ w+)',\\ s*'(?<schema>\\ w+)',\\ s*'(TABLE|COLUMN|INDEX|DEFAULT|CONSTRAINT)'.*?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
108- patterns .add (new SqlPattern ("EXEC(UTE)? core\\ .fn_dropifexists\\ s*'(\\ w+)',\\ s*'(?<schema>\\ w+)'.*?" + STATEMENT_ENDING_REGEX , Type .NonTable , Operation .Other ));
107+ patterns .add (new SqlPattern ("EXEC(UTE)? core\\ .fn_dropifexists\\ s*'(?<table>\\ w+)'\\ s* ,\\ s*'(?<schema>\\ w+)'\\ s* ,\\ s*'(TABLE|COLUMN|INDEX|DEFAULT|CONSTRAINT)'.*?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
108+ patterns .add (new SqlPattern ("EXEC(UTE)? core\\ .fn_dropifexists\\ s*'(\\ w+)'\\ s* ,\\ s*'(?<schema>\\ w+)'.*?" + STATEMENT_ENDING_REGEX , Type .NonTable , Operation .Other ));
109109
110- // Index names are prefixed with their associated table names on SQL Server
111- patterns .add (new SqlPattern (getRegExWithPrefix ( "DROP INDEX (IF EXISTS )?" ) , Type .Table , Operation .Other ));
110+ // DROP INDEX on SQL Server follows a similar pattern to CREATE INDEX (above)
111+ patterns .add (new SqlPattern ("DROP INDEX (IF EXISTS )?\\ w+ ON " + TABLE_NAME_REGEX + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
112112
113113 patterns .add (new SqlPattern ("(CREATE|ALTER) PROCEDURE .+?" + STATEMENT_ENDING_REGEX , Type .NonTable , Operation .Other ));
114114 }
115115 else
116116 {
117117 patterns .add (new SqlPattern ("ALTER TABLE " + TABLE_NAME_REGEX + " RENAME TO " + TABLE_NAME2_REGEX + STATEMENT_ENDING_REGEX , Type .Table , Operation .RenameTable ));
118118 patterns .add (new SqlPattern (getRegExWithPrefix ("CREATE (TEMPORARY )?TABLE " ), Type .Table , Operation .Other ));
119- patterns .add (new SqlPattern ("SELECT core\\ .fn_dropifexists\\ s*\\ ('(?<table>\\ w+)',\\ s*'(?<schema>\\ w+)',\\ s*'(TABLE|COLUMN|INDEX|DEFAULT|CONSTRAINT)'.+?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
120- patterns .add (new SqlPattern ("SELECT core\\ .fn_dropifexists\\ s*\\ ('(\\ w+)',\\ s*'(?<schema>\\ w+)'.+?" + STATEMENT_ENDING_REGEX , Type .NonTable , Operation .Other ));
119+ patterns .add (new SqlPattern ("SELECT core\\ .fn_dropifexists\\ s*\\ ('(?<table>\\ w+)'\\ s* ,\\ s*'(?<schema>\\ w+)'\\ s* ,\\ s*'(TABLE|COLUMN|INDEX|DEFAULT|CONSTRAINT)'.+?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
120+ patterns .add (new SqlPattern ("SELECT core\\ .fn_dropifexists\\ s*\\ ('(\\ w+)'\\ s* ,\\ s*'(?<schema>\\ w+)'.+?" + STATEMENT_ENDING_REGEX , Type .NonTable , Operation .Other ));
121121 patterns .add (new SqlPattern ("SELECT SETVAL\\ ('" + TABLE_NAME_NO_UNDERSCORE_REGEX + "_.+?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
122122 patterns .add (new SqlPattern (getRegExWithPrefix ("CLUSTER \\ w+ ON " ), Type .Table , Operation .Other )); // e.g. CLUSTER PK_Keyword ON flow.Keyword
123123 patterns .add (new SqlPattern (getRegExWithPrefix ("CLUSTER " ), Type .Table , Operation .Other ));
@@ -135,7 +135,7 @@ public String getReorderedScript(boolean isHtml)
135135 }
136136
137137 patterns .add (new SqlPattern ("ALTER TABLE " + TABLE_NAME_REGEX + " ADD CONSTRAINT \\ w+ FOREIGN KEY \\ ([^\\ )]+?\\ ) REFERENCES " + TABLE_NAME2_REGEX + " \\ ([^\\ )]+?\\ ).*?" + STATEMENT_ENDING_REGEX , Type .Table , Operation .Other ));
138- // Put this at the end to catch all other ALTER TABLE statements (i.e., not RENAMEs)
138+ // Put this at the end to capture all other ALTER TABLE statements (i.e., not RENAMEs)
139139 patterns .add (new SqlPattern (getRegExWithPrefix ("ALTER TABLE (IF EXISTS )?(ONLY )?" ), Type .Table , Operation .Other ));
140140
141141 Pattern commentPattern = compile (COMMENT_REGEX );
0 commit comments