diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 051efa719..be8681178 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -386,7 +386,26 @@ Similarly, we can generate a clustered unique constraint using:: UniqueConstraint("y", mssql_clustered=True), ) - .. versionadded:: 0.9.2 +.. versionadded:: 0.9.2 + +To explicitly request a non-clustered primary key (for example, when +a separate clustered index is desired), use:: + + Table('my_table', metadata, + Column('x', ...), + Column('y', ...), + PrimaryKeyConstraint("x", "y", mssql_clustered=False)) + +which will render the table, for example, as:: + + CREATE TABLE my_table (x INTEGER NOT NULL, y INTEGER NOT NULL, + PRIMARY KEY NONCLUSTERED (x, y)) + +.. versionchanged:: 1.1 the ``mssql_clustered`` option used to default to + False, now it defaults to None. ``mssql_clustered=False`` now explicitly + requests a non-clustered primary key and None relies on default SQL Server + behavior. + MSSQL-Specific Index Options ----------------------------- @@ -1460,8 +1479,12 @@ class MSDDLCompiler(compiler.DDLCompiler): self.preparer.format_constraint(constraint) text += "PRIMARY KEY " - if constraint.dialect_options['mssql']['clustered']: - text += "CLUSTERED " + clustered = constraint.dialect_options['mssql']['clustered'] + if clustered is not None: + if clustered: + text += "CLUSTERED " + else: + text += "NONCLUSTERED " text += "(%s)" % ', '.join(self.preparer.quote(c.name) for c in constraint) @@ -1572,7 +1595,7 @@ class MSDialect(default.DefaultDialect): construct_arguments = [ (sa_schema.PrimaryKeyConstraint, { - "clustered": False + "clustered": None }), (sa_schema.UniqueConstraint, { "clustered": False |