-
Notifications
You must be signed in to change notification settings - Fork 43
SQL constraint changes #3707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL constraint changes #3707
Conversation
4018db5 to
2ed6dc5
Compare
80394ee to
c300746
Compare
86da5f3 to
b4316c3
Compare
ImeevMA
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thank you for the patch. I have three comments, see them below.
| The constraint-name must be an identifier which is valid according to the rules for identifiers. | ||
| The constraint-name must be unique within the table. | ||
| A constraint name must be an identifier that is valid according to the rules for identifiers. | ||
| A constraint name must be unique within the table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exactly so. There cannot be another table foreign key (= tuple foreign key) constraint with the same name, but it is possible to have a CHECK or UNIQUE table constraint, as well as any column constraint (= field constraint) with the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed like this:
A constraint name must be unique within the table for a specific constraint type.
For example, the CHECK and FOREIGN KEY constraints can have the same name.
|
|
||
| Only one column in the table may be autoincrement. | ||
| However, it is legal to say ``PRIMARY KEY (a, b, c AUTOINCREMENT)`` -- in that case, there | ||
| are three columns in the primary key but only the first column (``a``) is AUTOINCREMENT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this by chance. This is not entirely true. I see that this was added to close #947, but in fact AUTOINCREMENT will be added here to column c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, changed to ... but only the third column (``c``) is AUTOINCREMENT.
| - A referenced column has a UNIQUE constraint. | ||
| - A referenced column has a UNIQUE index. | ||
|
|
||
| Note that before the :doc:`2.11.0 </release/2.11.0>` version, uniqueness of a foreign key is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more existence of an index on the referenced columns then uniqueness of a foreign key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to:
Note that before the :doc:`2.11.0 </release/2.11.0>` version, an index existence for the referenced columns is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``).
Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion.
b4316c3 to
6b55382
Compare
| - Every table must have one and only one primary key. | ||
| - Primary-key columns are automatically ``NOT NULL``. | ||
| - Primary-key columns are automatically indexed. | ||
| - Primary-key columns are unique, that is, it is illegal to have two rows that have the same values for the columns specified in the constraint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Primary-key columns are unique, that is, it is illegal to have two rows that have the same values for the columns specified in the constraint. | |
| - Primary-key columns are unique. That means it is illegal to have two rows with the same values for the columns specified in the constraint. |
| There is a shorthand: specifying UNIQUE in a :ref:`column definition <sql_column_def_constraint>`. | ||
|
|
||
| Unique constraints are similar to primary-key constraints, except that: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Unique constraints are similar to primary-key constraints, except that: | |
| * Unique constraints are similar to primary-key constraints, except that: | |
| a table may have any number of unique keys, and unique keys are not automatically ``NOT NULL``. | |
| * Unique columns are automatically indexed. | |
| * Unique columns are unique. That means it is illegal to have two rows with the same values in the unique-key columns. |
Let's make the formatting consistent
| - A referenced column has a UNIQUE index. | ||
|
|
||
| Note that before the :doc:`2.11.0 </release/2.11.0>` version, an index existence for the referenced columns is checked when creating a constraint (for example, using ``CREATE TABLE`` or ``ALTER TABLE``). | ||
| Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Starting with 2.11.0, this check is weakened and existence of an index is checked during data insertion. | |
| Starting with 2.11.0, this check is weakened and the existence of an index is checked during data insertion. |
|
|
||
| UNIQUE constraints look like this: |br| | ||
| :samp:`UNIQUE ({column-name} [, {column-name}...])` | ||
| UNIQUE constraints look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| UNIQUE constraints look like this: | |
| **UNIQUE constraints** | |
| UNIQUE constraints look like this: |
I think it's necessary to separate the paragraphs about PRIMARY | UNIQUE | CHECK constraints from each other somehow (with bold?). It's a bit difficult to figure out where a new paragraph starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will do
6b55382 to
c042ab0
Compare
https://docs.d.tarantool.io/en/doc/sql-constraint-mechanism/reference/reference_sql/sql_statements_and_clauses/#table-constraint-definition
https://docs.d.tarantool.io/en/doc/sql-constraint-mechanism/reference/reference_sql/sql_statements_and_clauses/#table-constraint-definition-for-foreign-keys