constraints

How to guarantee uniqueness when N tables have 1:1 relationship with a common table?

拟墨画扇 提交于 2019-12-04 17:26:46
Lets suppose I have a scenario with the following model: An Animal table which represents any animal, a Dog table and a Bird table, each one with a 1:1 relationship with the Animal table. Animal INTEGER id (PK) STRING name Bird INTEGER id (PK FK referencing `Animal.id`) Dog INTEGER id (PK FK referencing `Animal.id`) (I'm giving only the keys just to be clear) How can I guarantee that a given row in the Animal table will have JUST one referenced row in either the Dog or the Bird table? The model itself allows it... An animal can't be a Dog and a Bird at the same time ( not in mythology but that

Angular route parameters contraints

纵然是瞬间 提交于 2019-12-04 17:22:31
I'm coming from the Asp.net MVC world where route constraints are really useful. I'm currently developing an Angular JS SPA that incorporates client side routing. I would also like to add parameter constraints to my client-side routes as in: $.routeProvider.when("/post/:id/:name?") where I'd like to constrain my :id parameter to only be valid when these are numbers. I haven't found anything similar in Angular Docs (which are horrible to say the least). Can it be done? And maybe also parameter defaults? There's no built-in way to set route constraints, but you can do it pretty easily yourself

What is the difference between NSLayoutAttributeBaseline and NSLayoutAttributeBottom?

馋奶兔 提交于 2019-12-04 16:23:41
问题 The Apple docs usefully state that NSLayoutAttributeBaseline aligns to "The object’s baseline". What's a baseline? How is that different from the bottom? 回答1: Baseline applies to views such as UILabel . The baseline would be the position where the bottom of uppercase letters appear. For most other views (if not all others) the baseline and the bottom are the same. 回答2: NSLayoutAttributeBaseline NSLayoutAttributeBottom 来源: https://stackoverflow.com/questions/14883439/what-is-the-difference

CGAL - custom 2D point and intersection behavior in constrained delaunay triangulation

淺唱寂寞╮ 提交于 2019-12-04 14:28:53
In short, I have to generate a constrained delaunay triangulation from a set of 2D points that carry additional information. Since there could be intersecting constraints, I need that the triangulation properly interpolates the satellite data whenever it generates the new point of intersection. I tried with CGAL (C++) to define a custom kernel following the example here , but I've failed to compile it succesfully, basically because there is something fundamental of the underlying generic programming machinery of CGAL that I am missing (lot of type mismatches etc.). Can you point me to a

Access Auto Layout Constraint Programmatically

狂风中的少年 提交于 2019-12-04 12:59:19
I have a view that has a lot of subviews, I will refer to these views as superview, subview A, subview B, subview C, etc. So I need to access the trailing space constraint I set on subView A to superview and modify it. This constraint would appear in superview.constraints. However, all the subviews have leading/trailing space constraints set between them and the superview. So, if I log superview.constraints, it would look like this: <__NSArrayM 0xac744e0>( <NSLayoutConstraint:0x98f3500 H:|-(0)-[UILabel:0x98f2190] (Names: '|':HeaderReusableView:0x98f1f40 )>, <NSLayoutConstraint:0x98f3540 H:

Compound UniqueConstraint with a function

前提是你 提交于 2019-12-04 12:38:14
A quick SQLAlchemy question... I have a class "Document" with attributes "Number" and "Date". I need to ensure that there's no duplicated number for the same year , is there a way to have a UniqueConstraint on "Number + year(Date)"? Should I use a unique Index instead? How would I declare the functional part? (SQLAlchemy 0.5.5, PostgreSQL 8.3.4) Thanks in advance! Ants Aasma You should use a functional unique index to apply this constraint. Unfortunately the database generic database independent schema definition machinery in SQLAlchemy doesn't abstract functional indexes yet. You'll have to

Best way to prevent unique constraint violations with JPA

▼魔方 西西 提交于 2019-12-04 12:33:06
问题 I have an Keyword and a KeywordType as entities. There are lots of keywords of few types. When trying to persist the second keyword of a type, the unique constraint is violated and the transaction is rolled back. Searching SO i found several possibilies (some of them from different contexts, so I'm not sure of their validity here) - this post and this post advise catching the Exception which would be of no use to me as I end up where I started and still need to somehow persist the keyword.

Unique Constraint for Bit Column Allowing Only 1 True (1) Value

安稳与你 提交于 2019-12-04 10:55:53
I have this table: CREATE TABLE [tblExample]( [ExampleID] [int] IDENTITY(1,1) NOT NULL, [WordsAndStuff] [nvarchar](max) NOT NULL, [Active] [bit] NOT NULL I want the Active column to have a unique constraint that will only allow one record to be true (1). At this point, I don't need there to BE a true record all the time, there just cannot be more than one of them. How do I write the constraint? Just one active record at a time in the table? You can use a unique index with a filter: create unique nonclustered index uixf_tblExample_Active_filtered on tblExample (Active) include (ExampleId,

SQL Server add a column constraint to limit data to -1 to 1

淺唱寂寞╮ 提交于 2019-12-04 10:29:39
I want to constrain a SQL Server decimal column to only allow -1,0,1 as valid values. Can you show me the SQL syntax for adding such a constraint. (I would like to know how to do it in both the CREATE TABLE statement and/or the ALTER TABLE ADD CONSTRAINT). Or can this only be accomplished in a trigger? gbn CREATE TABLE foo ( bar int NOT NULL CONSTRAINT CK_foo_bar CHECK (bar IN (-1, 0, 1)) ) or ALTER TABLE foo WITH CHECK ADD --added WITH CHECK CONSTRAINT CK_foo_bar CHECK (bar IN (-1, 0, 1)) --not needed "FOR bar" Edit: thoughts... why constrain a decimal? Can you change it to smallint or int?

SQL Server 2005: Nullable Foreign Key Constraint

◇◆丶佛笑我妖孽 提交于 2019-12-04 10:16:39
问题 I have a foreign key constraint between tables Sessions and Users. Specifically, Sessions.UID = Users.ID. Sometimes, I want Sessions.UID to be null. Can this be allowed? Any time I try to do this, I get an FK Constraint Violation. Specifically, I'm inserting a row into Sessions via LINQ. I set the Session.User = null; and I get this error: An attempt was made to remove a relationship between a User and a Session. However, one of the relationship's foreign keys (Session.UID) cannot be set to