bbotella commented on code in PR #3562: URL: https://github.com/apache/cassandra/pull/3562#discussion_r1920267036
########## doc/modules/cassandra/pages/developing/cql/constraints.adoc: ########## @@ -0,0 +1,93 @@ += Constraints + +Constraints provide a way of specifying and enforcing conditions at a +column level in a table schema definition and enforcing them at write time. + +== CREATE CONSTRAINT + +Constraints can be created within the column definition, or as part +of the table properties. + +The main syntaxis to define a constraint is as follows: + +[source,bnf] +---- +CREATE TABLE keyspace.table ( + name text, + i int CHECK (condition) (AND (condition))* + ..., + +); +---- + +As shown in this syntax, more than one constraint can be defined for a given column using the AND keyword. + +== ALTER CONSTRAINT + +Altering a constraint is done by following the alter column CQL syntax: +[source,bnf] +---- +ALTER TABLE [IF EXISTS] <table> ALTER [IF EXISTS] <column> CHECK <condition>; +---- + +== DROP CONSTRAINT +And DROP can be used to drop constraints for a column as well. +[source,bnf] +---- +ALTER TABLE [IF EXISTS] <table> ALTER [IF EXISTS] <column> DROP CHECK; +---- + +== AVAILABLE CONSTRAINTS + +=== SCALAR CONSTRAINT + +Defines a comparator against a numeric type. It support all numeric types supported in Cassandra, with all the regular +comparators. + +For example, we can define constraints that ensure that i is bigger or equal than 100 but smaller than 1000. + +[source,bnf] +---- +CREATE TABLE keyspace.table ( + name text, + i int CHECK i < 1000 AND i > 100 + ..., +); +---- + +Altering that constraint can be done with: + +---- +ALTER TABLE keyspace.table ALTER i CHECK i >= 500; +---- + +Finally, the constraint can be removed: + +---- +ALTER TABLE keyspace.table ALTER i DROP CHECK; +---- + +=== LENGTH CONSTRAINT + +Defines a condition that checks the lenght of text or binary type. Review Comment: length is a hard word :-( -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

