String sql = createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA);    Pattern        declarePattern    = new Perl5Compiler().compile("DECLARE @([\\S]+) [^@]+@([\\S]+)"); PatternMatcher matcher           = new Perl5Matcher(); String         tableNameVar      = "tablename"; String         constraintNameVar = "constraintname";  if (matcher.contains(sql, declarePattern)) { tableNameVar      = matcher.getMatch().group(1); constraintNameVar = matcher.getMatch().group(2); }
    public void testColumnConstraints() throws Exception    {        // this is not valid sql as a table can have only one identity column at most         assertEqualsIgnoringWhitespaces(            "SET quoted_identifier on;\n"+            "SET quoted_identifier on;\n"+            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'constraints')\n"+            "BEGIN\n"+            "  DECLARE @tablename nvarchar(256), @constraintname nvarchar(256)\n"+            "  DECLARE refcursor CURSOR FOR\n"+            "  SELECT object_name(objs.parent_obj) tablename, objs.name constraintname\n"+            "    FROM sysobjects objs JOIN sysconstraints cons ON objs.id = cons.constid\n"+            "    WHERE objs.xtype != 'PK' AND object_name(objs.parent_obj) = 'constraints'  OPEN refcursor\n"+            "  FETCH NEXT FROM refcursor INTO @tablename, @constraintname\n"+            "  WHILE @@FETCH_STATUS = 0\n"+            "    BEGIN\n"+            "      EXEC ('ALTER TABLE '+@tablename+' DROP CONSTRAINT '+@constraintname)\n"+            "      FETCH NEXT FROM refcursor INTO @tablename, @constraintname\n"+            "    END\n"+            "  CLOSE refcursor\n"+            "  DEALLOCATE refcursor\n"+            "  DROP TABLE \"constraints\"\n"+            "END;\n"+            "SET quoted_identifier on;\n"+            "CREATE TABLE \"constraints\"\n"+            "(\n"+            "    \"COL_PK\"               VARCHAR(32),\n"+            "    \"COL_PK_AUTO_INCR\"     INT IDENTITY(1,1),\n"+            "    \"COL_NOT_NULL\"         BINARY(100) NOT NULL,\n"+            "    \"COL_NOT_NULL_DEFAULT\" FLOAT DEFAULT -2.0 NOT NULL,\n"+            "    \"COL_DEFAULT\"          CHAR(4) DEFAULT 'test',\n"+            "    \"COL_AUTO_INCR\"        DECIMAL(19,0) IDENTITY(1,1),\n"+            "    PRIMARY KEY (\"COL_PK\", \"COL_PK_AUTO_INCR\")\n"+            ");\n",            createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));    }