constraints

Postgres constraint for unique datetime range

我们两清 提交于 2019-11-27 03:32:24
问题 My table has two columns: startsAt endsAt Both hold date and time. I want to make following constraint: IF both columns are NOT NULL then range between startsAt and endsAt must not overlap with other ranges (from other rows). 回答1: You can keep your separate timestamp columns and still use an exclusion constraint on an expression: CREATE TABLE tbl ( tbl_id serial PRIMARY KEY , starts_at timestamp , ends_at timestamp , EXCLUDE USING gist (tsrange(starts_at, ends_at) WITH &&) -- no overlapping )

SQL Server 2008- Get table constraints

安稳与你 提交于 2019-11-27 03:31:36
Could you help me frame a query that retrieves the constraints in all the tables, the count of constraints in each table, and also display NULL for tables that do NOT have any constraints. Thx in advance! This is what I have so far: Select SysObjects.[Name] As [Constraint Name] , Tab.[Name] as [Table Name], Col.[Name] As [Column Name] From SysObjects Inner Join (Select [Name],[ID] From SysObjects) As Tab On Tab.[ID] = Sysobjects.[Parent_Obj] Inner Join sysconstraints On sysconstraints.Constid = Sysobjects.[ID] Inner Join SysColumns Col On Col.[ColID] = sysconstraints.[ColID] And Col.[ID] = Tab

Prolog Constraint Processing : Packing Squares

一世执手 提交于 2019-11-27 03:02:46
问题 I'm trying to solve a constraint processing problem in prolog. I need to pack 4 squares of 5x5,4x4,3x3 and 2x2 in a grid of 10x10. They may not overlap. My variables look like this: Name: SqX(i), i=1..10, domain: 1..10 Where X is either 5,4,3 or 2. The index i represents the row, the domain the column in the grid. My first constraints try to define the width and height of the squares. I formulate it as such: Constraint: SqX(i) > SqX(j)-X /\ i>j-X, range: i>0 /\ j>0 So that the possible points

Foreign key vs check constraint for integrity

混江龙づ霸主 提交于 2019-11-27 02:46:25
问题 I am building a system that is a central repository for storing data from a number of other systems. A sync process is required to update the central repository when the other systems data is updated. There will be a sync_action table to identify which system the central repo needs to sync with and the type of sync required. There are set of defined actions that is very unlikely to change. A slimmed down system is below. As I see it I can approach this in two ways: Option 1 ) Have an Action

Display names of all constraints for a table in Oracle SQL

佐手、 提交于 2019-11-27 02:39:20
I have defined a name for each of the constraint for the multiple tables that I have created in Oracle SQL. The problem is that to drop a constraint for the column of a particular table I need to know the name that I have supplied for each constraints, which I have forgotten. How do I list out all the names of constraints that I have specified for each column of a table? Is there any SQL statement for doing so? Ollie You need to query the data dictionary , specifically the USER_CONS_COLUMNS view to see the table columns and corresponding constraints: SELECT * FROM user_cons_columns WHERE table

How to handle JPA unique constraint violations?

巧了我就是萌 提交于 2019-11-27 02:33:33
问题 When a unique constraint is violated, a javax.persistence.RollbackException is thrown. But there could be multiple reasons to throw a RollbackException . How can I find out that a unique constraint was violated? try { repository.save(article); } catch(javax.persistence.RollbackException e) { // how to find out the reason for the rollback exception? } 回答1: How can I find out that a unique constraint was violated? Exception are chained, you have to call getCause() recursively to get the

How to create a “unique” constraint on a boolean Mysql column?

谁说胖子不能爱 提交于 2019-11-27 02:13:23
问题 I would like to add a BOOLEAN column to a MySQL table which will be named is_default . In this column, only one record can have is_default set to true . How can I add this constraint to my column with mysql? Thanks! UPDATE If it is not a constraint that I should add. How are we dealing with this type of problem on DBs? 回答1: I think this is not the best way to model the situation of a single default value. Instead, I would leave the IsDefault column out and create a separate table with one row

Disabling foreign key constraint, still can't truncate table? (SQL Server 2005)

ぐ巨炮叔叔 提交于 2019-11-27 02:04:15
问题 I have a table called PX_Child that has a foreign key on PX_Parent. I'd like to temporarily disable this FK constraint so that I can truncate PX_Parent. I'm not sure how this goes however. I've tried these commands ALTER TABLE PX_Child NOCHECK CONSTRAINT ALL ALTER TABLE PX_Parent NOCHECK CONSTRAINT ALL (truncate commands) ALTER TABLE PX_Child CHECK CONSTRAINT ALL ALTER TABLE PX_Parent CHECK CONSTRAINT ALL But the truncate still tells me it can't truncate PX_Parent because of a foreign key

Multiple constraints in table: How to get all violations?

蓝咒 提交于 2019-11-27 01:57:40
问题 I have a table in Oracle with several constraints. When I insert a new record and not all constraints are valid, then Oracle raise only the "first" error. How to get all violations of my record? CREATE TABLE A_TABLE_TEST ( COL_1 NUMBER NOT NULL, COL_2 NUMBER NOT NULL, COL_3 NUMBER NOT NULL, COL_4 NUMBER NOT NULL ); INSERT INTO A_TABLE_TEST values (1,null,null,2); ORA-01400: cannot insert NULL into ("USER_4_8483C"."A_TABLE_TEST"."COL_2") I would like to get something like this: Column COL_2:

Is there a generic constraint I could use for the + operator?

╄→гoц情女王★ 提交于 2019-11-27 01:57:33
is there some 'where' type contraints in can add to make the follwing code compile ? public class Plus<T> : BinaryOperator<T> where T : ... { public override T Evaluate(IContext<T> context) { return left.Evaluate(context) + right.Evaluate(context); } } Thanks :) Marc Gravell There are no such devices in C#. A few options are available, though: in C# 4.0 and .NET 4.0 (or above), use dynamic , which supports + but offers no compile time checking in .NET 3.5 (or above), MiscUtil offers an Operator class which makes operators available as methods - again, without any compile-time checking So