constraints

Unique values for two columns in Doctrine

醉酒当歌 提交于 2019-12-23 18:23:05
问题 I have entity called Dimension. It has three attributes - ID, width and height. ID is primary key. In the table, the dimension should be unique so there has to be only one record with given dimension (for example 40x30). What constraints I need to set? Is uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})} correct? 回答1: From the documentation, @UniqueConstraint annotation is used inside the @Table annotation on the entity-class level. It allows to hint the

Compute a list of distinct odd numbers (if one exists), such that their sum is equal to a given number

混江龙づ霸主 提交于 2019-12-23 18:04:17
问题 :- use_module(library(clpfd)). % load constraint library % [constraint] Compute a list of distinct odd numbers (if one exists), such that their sum is equal to a given number. odd(Num) :- Num mod 2 #= 1. sumOfList([],N,N) :- !. sumOfList([H|T],Counter,N) :- NewN #= H + Counter, sumOfList(T,NewN,N). buildOddList(N,InputList,L) :- %return list when sum of list is N V in 1..N, odd(V), append(InputList,[V],TempL), sumOfList(TempL,0,N)-> L = TempL; buildOddList(N,TempL,L). computeOddList(N) :-

Get row to swap tables on a certain condition

二次信任 提交于 2019-12-23 17:19:39
问题 I currently have a parent table: CREATE TABLE members ( member_id SERIAL NOT NULL, UNIQUE, PRIMARY KEY first_name varchar(20) last_name varchar(20) address address (composite type) contact_numbers varchar(11)[3] date_joined date type varchar(5) ); and two related tables: CREATE TABLE basic_member ( activities varchar[3]) INHERITS (members) ); CREATE TABLE full_member ( activities varchar[]) INHERITS (members) ); If the type is full the details are entered to the full_member table or if type

Is it possible to get a legit range info when using a SMT constraint with Z3

痴心易碎 提交于 2019-12-23 16:09:24
问题 So basically I am trying to solve the following SMT constraint with a generic constraint solver like Z3: >>> from z3 import * >>> a = BitVec("a", 32) >>> b = BitVec("b", 32) >>> c1 = (a + 32) & (b & 0xff) >>> c2 = (b & 0xff) >>> s = Solver() >>> s.add(c1 == c2) >>> s.check() sat >>> s.model() [b = 0, a = 4294967199] Note that obviously, the constraint should be sat whenever b falls within the range of [0x00000000, 0xffffff00] . So here is my question, is it in general feasible for a SMT

How to change primary key of a record in sqlite?

*爱你&永不变心* 提交于 2019-12-23 13:08:50
问题 I have table that has a TEXT primary key CREATE TABLE tbl1{ a1 TEXT PRIMARY KEY, ... ); (the a1 column is a foreign key inside another table) How can I change values of a1 ? If I do UPDATE tbl1 SET a1 = ? WHERE a1 = ? I get a constrain violation error 回答1: You should never change primary keys; it would be a better idea to use an INTEGER PRIMARY KEY and have the actual URL be a normal data column. If you really want change a key that is the target of a foreign key, you should declare the

Minimum length constraint on a column

旧时模样 提交于 2019-12-23 12:43:44
问题 I'm trying to implement a minimum length constraint in Oracle. As I read in this answer and multiple other similar questions I tried: ALTER TABLE my_table ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (DATALENGTH(password) >=4) And I am getting "DATALENGTH": invalid identifier" . I also tried: ( DATALENGTH([password]) >=4 ) ( LEN([password]) >=4 ) ( LEN(password) >=4 ) What is the current format for this check constraint in Oracle? 回答1: DATALENGTH() returns the length in bytes in SQL Server . The

Stop Hibernate from creating not-null constraints

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:18:34
问题 Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create ? 回答1: From the documentation of Hibernate Validator: 6.1. Database schema-level validation Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated @NotNull , its columns will be

Error:“Key … is not present in table”

邮差的信 提交于 2019-12-23 10:24:02
问题 I have a table with a character varying(12) field in it which is its PRIMARY KEY. I ran this query SELECT * FROM bg WHERE bg_id ='470370111002' It selects a row from the table. All looks good. Then I try. INSERT INTO csapp_center_bgs(bg_id,center_id) VALUES('470370111002',2) There is a foreign key on bg_id that looks like... ALTER TABLE csapp_center_bgs ADD CONSTRAINT csapp_center_bgs_bg_id_65c818f360c84dc5_fk_bg_bg_id FOREIGN KEY (bg_id) REFERENCES tiger.bg (bg_id) MATCH SIMPLE ON UPDATE NO

Query Oracle constrain after search_condition's value

房东的猫 提交于 2019-12-23 09:50:40
问题 I want to find a constraint in Oracle SQL that has a certain search_condition. Something like this: SELECT constraint_name, constraint_type,search_condition FROM USER_CONSTRAINTS WHERE table_name ='MYTABLE' AND search_condition = '"myColumn" IS NOT NULL'; Problem is i get error "Ilegal use of datatype LONG". I'd appreciate a working alternative. Thanks! 回答1: Amend the second half of your WHERE clause as follows SUBSTR(search_condition, 1, 21) = 'whatever you're after' search_condition is a

SQL Server: Deleting Rows with Foreign Key Constraints: Can Transactions override the constraints?

£可爱£侵袭症+ 提交于 2019-12-23 09:34:35
问题 I have a few tables where Foreign Key constraints are added. These are used with code generation to set up specific joins in generated stored procedures. Is it possible to override these constraints by calling multiple deletes within a transaction, specifically "TransactionScope" in C# or is cascaded deleting absolutely required? 回答1: Do not use cascade delete, you can cause serious performance issues that way. The best procedure is to do the deletes in order from the lowest child table up to