constraints

MySQL variables in ALTER TABLE script

家住魔仙堡 提交于 2019-12-01 05:05:32
问题 Hello The following procedure will have to move all constraints from one table to the other however I am having some difficulties at the point where the constraint should be deleted. The problem: how do I use variables in the following line ALTER TABLE var_referenced_table_name DROP FOREIGN KEY var_constraint_name; when I use as is, I receive the following error Error Code: 1146. Table 'oaf_businesslink_dev.var_referenced_table_name' doesn't exist MySQL does not recognise var_referenced_table

deferred constraint checking

蹲街弑〆低调 提交于 2019-12-01 05:04:34
Currently In our database design we have an circular reference between two entities. In other words, we have foreign keys in each table that reference each others primary key. In order to insert records in these tables we need to perform a deferred constraint checking. Is this possible in SQL Server 2008? I know Oracle DDL has special syntax for this. Aaron Alton There is no native way to do deferred constraint checking in SQL Server. Likely your best option is to insert a NULL value into the foreign key column in the first table until the second record is inserted, and then as part of the

Combining the UNIQUE and CHECK constraints

若如初见. 提交于 2019-12-01 04:50:45
问题 I have a table with columns a b and c, and if c is false then I only want to allow insertions if columns a and b are unique, but if c is true then a and b do not need to be unique. Example: There can only be one (foo, bar, false) in the table, but no limit on how many (foo, bar, true) there can be. I tried something like CONSTRAINT blah UNIQUE (a,b) AND CHECK (C is TRUE) but I can't figure out the correct syntax. 回答1: Create an indexed view returning a and b with a filter WHERE C = false ,

In SQL Server 2005, how do I set a column of integers to ensure values are greater than 0?

时光怂恿深爱的人放手 提交于 2019-12-01 04:17:48
This is probably a simple answer but I can't find it. I have a table with a column of integers and I want to ensure that when a row is inserted that the value in this column is greater than zero. I could do this on the code side but thought it would be best to enforce it on the table. Thanks! I was in error with my last comment all is good now. You can use a check constraint on the column. IIRC the syntax for this looks like: create table foo ( [...] ,Foobar int not null check (Foobar > 0) [...] ) As the poster below says (thanks Constantin), you should create the check constraint outside the

Hibernate: duplicate key value violates unique constraint

╄→гoц情女王★ 提交于 2019-12-01 04:06:07
I am trying to insert into a new record to my postgresql using Hibernate and Java EE. This is my model: @Entity @SuppressWarnings("serial") @Inheritance(strategy=InheritanceType.JOINED) public class BaseDesign implements Serializable { @Id @Expose @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", updatable = false, nullable = false) private Long id; @Version @Column(name = "version") private int version; @Expose @Column(name = "name") private String name; // getter and setter } And here is my import.sql INSERT INTO basedesign (id, name, version) VALUES (1, 'China', 0);

How to make a foreign key with a constraint on the referenced table in PostgreSQL

为君一笑 提交于 2019-12-01 03:56:42
问题 Suppose I have the following tables CREATE TABLE plugins ( id int primary key, type text); insert into plugins values (1,'matrix'); insert into plugins values (2,'matrix'); insert into plugins values (3,'function'); insert into plugins values (4,'function'); CREATE TABLE matrix_params ( id int primary key, pluginid int references plugins (id) ); This all works as expected but I would like to add an additional constraint that a matrix_param can only refer to the pluginid that has type 'matrix'

Unique constraint on multiple fields in Access 2003

浪尽此生 提交于 2019-12-01 03:51:30
I have not found any answer regarding my question, all unique constraint questions did not involve MS Access. The question is how to make a unique constraint on multpile fields in MS Access 2003 database? If my table consists of columns id, A, B, C, D, E, F . I have an index on column id , but I would like to have a unique constraint set on both columns A and B . Hence, I may have a duplicate value in column A , provided the value in column B are different. I want to stress that I am not interested in a workaround like creating new column with concatenated values from columns A and B , and

Create constraint in alter table without checking existing data

僤鯓⒐⒋嵵緔 提交于 2019-12-01 03:45:25
问题 I'm trying to create a constraint on the OE.PRODUCT_INFORMATION table which is delivered with Oracle 11g R2. The constraint should make the PRODUCT_NAME unique. I've tried it with the following statement: ALTER TABLE PRODUCT_INFORMATION ADD CONSTRAINT PRINF_NAME_UNIQUE UNIQUE (PRODUCT_NAME); The problem is, that in the OE.PRODUCT_INFORMATION there are already product names which currently exist more than twice. Executing the code above throws the following error: an alter table validating

Displaying the constraints in a table

南笙酒味 提交于 2019-12-01 03:24:44
Hello I am trying to display the constraints in one of my tables but for some reason I get the message no rows selected. Noted below is the table I have created. Create table Teams ( TeamID varCHAR2(4) constraint Teams_TeamID_PK Primary Key, TeamName VARCHAR2(40) ); This is the code I am using to show my constraints. SELECT constraint_name, constraint_type, search_condition FROM USER_CONSTRAINTS WHERE table_name = 'Teams'; I am a rookie so I want to make sure I understand what is wrong. I have tried to drop the table thinking that my constraints did not take - I did not, nor did I receive any

Exclusion constraint on a bitstring column with bitwise AND operator

天涯浪子 提交于 2019-12-01 03:02:46
问题 So I was just reading about Exclusion Constraints in PostgreSQL and I couldn't seem to find a way to use bitwise operators on bitstrings, and I was wondering if it was possible. My use case is I have a name: text column and a value: bit(8) column. And I wanted to create a constraint that basically says this: ADD CONSTRAINT route_method_overlap EXCLUDE USING gist(name WITH =, value WITH &) But this doesn't work since operator &(bit,bit) is not a member of operator family "gist_bit_ops" I