constraints

How to constrain a database table so only one row can have a particular value in a column?

我是研究僧i 提交于 2019-12-30 01:53:27
问题 Using Oracle, if a column value can be 'YES' or 'NO' is it possible to constrain a table so that only one row can have a 'YES' value? I would rather redesign the table structure but this is not possible. [UDPATE] Sadly, null values are not allowed in this table. 回答1: Use a function-based index: create unique index only_one_yes on mytable (case when col='YES' then 'YES' end); Oracle only indexes keys that are not completely null, and the CASE expression here ensures that all the 'NO' values

How to manage the gap between two views in auto layout

冷暖自知 提交于 2019-12-29 09:41:33
问题 I am using auto layout for my ViewController I know how to define the gap between two views using constraints programmatically. What I want to do now is when the screen size increase, increase the gap also. Because my UIViews are positioned properly in iphone 4s and 5s but in 6 and 6 plus they are positioned in a small area of the screen. I know adding multiplier we can set the aspect ratio of a view but, how to increase the gap between 2 views when the screen hight increase. UPDATE Let say

How to keep foreign key relations consistent in a “diamond-shaped” system of relationships

限于喜欢 提交于 2019-12-29 07:04:27
问题 Consider this situation: a Car is bought from a Salesperson . A Salesperson works at a Showroom (and at only one Showroom). A Showroom is affiliated to a Manufacturer , and only sells cars made by that Manufacturer. At the same time, a Car is of a particular Model , and a Model is made by a Manufacturer. Restriction R: A Car's Model's Manufacturer must be the same Manufacturer as the Car's Salesperson's Showroom's affiliated Manufacturer. The diagram shows the obvious foreign key

How to keep foreign key relations consistent in a “diamond-shaped” system of relationships

纵饮孤独 提交于 2019-12-29 07:04:20
问题 Consider this situation: a Car is bought from a Salesperson . A Salesperson works at a Showroom (and at only one Showroom). A Showroom is affiliated to a Manufacturer , and only sells cars made by that Manufacturer. At the same time, a Car is of a particular Model , and a Model is made by a Manufacturer. Restriction R: A Car's Model's Manufacturer must be the same Manufacturer as the Car's Salesperson's Showroom's affiliated Manufacturer. The diagram shows the obvious foreign key

How to set constraints on generic types in Java?

喜欢而已 提交于 2019-12-29 04:27:10
问题 I have a generic class: public class ListObject<T> { // fields protected T _Value = null; // .. } Now I want to do something like the following: ListObject<MyClass> foo = new ListObject<MyClass>(); ListObject<MyClass> foo2 = new ListObject<MyClass>(); foo.compareTo(foo2); Question: How can I define the compareTo() method with resprect to the generic T ? I guess I have to somehow implement a constraint on the generic T , to tell that T implements a specific interface (maybe Comparable , if

Controlling distance of shuffling

自古美人都是妖i 提交于 2019-12-28 05:33:04
问题 I have tried to ask this question before, but have never been able to word it correctly. I hope I have it right this time: I have a list of unique elements. I want to shuffle this list to produce a new list. However, I would like to constrain the shuffle, such that each element's new position is at most d away from its original position in the list. So for example: L = [1,2,3,4] d = 2 answer = magicFunction(L, d) Now, one possible outcome could be: >>> print(answer) [3,1,2,4] Notice that 3

Does a Postgres UNIQUE constraint imply an index?

岁酱吖の 提交于 2019-12-28 04:31:07
问题 When adding a unique constraint to a Postgres table does that imply that an index has also been added to that table? Meaning, if I add a UNIQUE constraint on a text column, does that text column now have an index or does an index have to be added separately? 回答1: Yes. UNIQUE constraints are implemented using a btree index in Postgres. Details: How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use? 来源: https://stackoverflow.com/questions/29655439/does-a-postgres

How do you drop a default value or similar constraint in T-SQL?

落爺英雄遲暮 提交于 2019-12-28 03:38:12
问题 I know the syntax: ALTER TABLE [TheTable] DROP CONSTRAINT [TheDefaultConstraint] but how to I drop the default constraint when I don't know its name? (That is, it was autogenerated at CREATE TABLE time.) 回答1: If you want to do this manually, you can use Management Studio to find it (under the Constraints node inside the table). To do it using SQL: If the constraints are default constraints, you can use sys.default_constraints to find it: SELECT OBJECT_NAME(parent_object_id) AS TableName, name

Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5

喜你入骨 提交于 2019-12-27 10:22:12
问题 I understand the old Struts and Springs method of aligning, sizing and distributing views in Interface Builder. However, I cannot seem to figure out how to evenly distribute views using auto layout with Xcode 5. There was a way to do it using Xcode 4, but that option is gone. I have 7 buttons arranged in a vertical stack. On a 3.5" layout, it looks great. When I preview the screen in the 4" layout, all of the buttons remain tightly packed and there is a large amount of space below the last

How to write OCL contraint

允我心安 提交于 2019-12-25 16:24:59
问题 I am new to OCL, I am using papyrus on eclipse luna 4.4.2 I have a class diagram named CLIENT with the constraint {all attributes are out of scope} a second class named Customer with the constraint {all attributes are mandatory} and another class call Address having an attribute provenance with the constraint {provenance shall be mandatory} How should I write the OCL constraint that suit the formal language? will also like to know how to verify the correctness of the syntax? 回答1: In case of