constraints

sql unique constraint on a 2 columns combination

谁都会走 提交于 2019-11-26 17:09:52
问题 How can you create a unique constraint on a combination of two values in two columns. meaning column1 column2 2 1 looking for the constraint to disallow column1 column2 1 2 回答1: If your database allows expressions in an index you can do something like this (ANSI SQL): CREATE UNIQUE INDEX on your_table (least(column1, column2) , greatest(column1, column2)); Note this is a unique index not a unique constraint. The only difference for most DBMS is that you can't have a unique index as the target

Constraint defined DEFERRABLE INITIALLY IMMEDIATE is still DEFERRED?

陌路散爱 提交于 2019-11-26 16:40:57
In connection with this answer I stumbled upon a phenomenon I cannot explain. Version: PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc-4.4.real (Debian 4.4.5-8) 4.4.5, 64-bit Consider the following demo. Testbed: CREATE TEMP TABLE t ( id integer ,txt text ,CONSTRAINT t_pkey PRIMARY KEY (id) DEFERRABLE INITIALLY IMMEDIATE ); INSERT INTO t VALUES (1, 'one') ,(2, 'two'); 1) UPDATE statement modifying multiple rows: UPDATE t SET id = t_old.id FROM t t_old WHERE (t.id, t_old.id) IN ((1,2), (2,1)); It seems there is a bug in the current implementation? The above UPDATE works though it

SQL constraint minvalue / maxvalue?

随声附和 提交于 2019-11-26 16:30:54
问题 Is there a way to set a SQL constraint for a numeric field that min value should be 1234 and max value should be 4523? 回答1: SQL Server syntax for the check constraint: create table numbers ( number int not null check(number >= 1234 and number <= 4523), ... ) create table numbers ( number int not null, check(number >= 1234 and number <= 4523), ... ) create table numbers ( number int not null, constraint number_range_check check(number >= 1234 and number <= 4523), ... ) 回答2: CREATE TABLE

Why can't I use a type argument in a type parameter with multiple bounds?

我是研究僧i 提交于 2019-11-26 16:15:18
So, I understand that the following doesn't work, but why doesn't it work? interface Adapter<E> {} class Adaptulator<I> { <E, A extends I & Adapter<E>> void add(Class<E> extl, Class<A> intl) { addAdapterFactory(new AdapterFactory<E, A>(extl, intl)); } } The add() method gives me a compile error, "Cannot specify any additional bound Adapter<E> when first bound is a type parameter" (in Eclipse), or "Type parameter cannot be followed by other bounds" (in IDEA), take your pick. Clearly you're just Not Allowed to use the type parameter I there, before the & , and that's that. (And before you ask,

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

て烟熏妆下的殇ゞ 提交于 2019-11-26 16:13:30
问题 I have a form which has around 12/13 fields. I used a Scrollview inside a constraint layout. Below is the hierarchy of the XML layout. The problem is, it doesn't scroll to the bottom instead scrolls only to the first initial 10 views. The last 3 fields gets hidden as the view does not scroll any further. PARENT LAYOUT <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http:/

MySQL distinction between e and é (e acute) - UNIQUE index

 ̄綄美尐妖づ 提交于 2019-11-26 16:08:16
问题 I have a table, students , with 3 columns: id , name , and age . I have a UNIQUE index Index_2 on columns name and age . CREATE TABLE `bedrock`.`students` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(45) NOT NULL, `age` INTEGER UNSIGNED NOT NULL, PRIMARY KEY (`id`), UNIQUE INDEX `Index_2` USING BTREE(`name`, `age`) ) ENGINE = InnoDB; I tried this insert option: insert into students (id, name, age) values (1, 'Ane', 23); which works ok. Than I've tried this one (see Ané - e

F# Static Member Type Constraints

烈酒焚心 提交于 2019-11-26 16:07:34
问题 I'm trying to define a function, factorize, which uses structural type constraints (requires static members Zero, One, +, and /) similar to Seq.sum so that it can be used with int, long, bigint, etc. I can't seem to get the syntax right, and can't find a lot of resources on the subject. This is what I have, please help. let inline factorize (n:^NUM) = ^NUM : (static member get_Zero: unit->(^NUM)) ^NUM : (static member get_One: unit->(^NUM)) let rec factorize (n:^NUM) (j:^NUM) (flist: ^NUM

How to trap on UIViewAlertForUnsatisfiableConstraints?

﹥>﹥吖頭↗ 提交于 2019-11-26 14:49:58
I'm seeing an error appear in my debugger log: Will attempt to recover by breaking constraint <NSLayoutConstraint:0x191f0920 H:[MPKnockoutButton:0x17a876b0]-(34)-[MPDetailSlider:0x17a8bc50](LTR)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. How do I trap on that call? It does not appear anywhere in my code. Tom Calmon This post helped me A LOT ! I added UIViewAlertForUnsatisfiableConstraints symbolic breakpoint with

Multiple column foreign key contraints

寵の児 提交于 2019-11-26 14:47:03
问题 I want to setup table constraints for the following scenario and I’m not sure how to do it or if it’s even possible in SQL Server 2005. I have three tables A,B,C. C is a child of B. B will have a optional foreign key(may be null) referencing A. For performance reasons I also want table C to have the same foreign key reference to table A. The constraint on table C should be that C must reference its parent (B) and also have the same foreign key reference to A as its parent. Anyone have any

How to write a constraint concerning a max number of rows in postgresql?

ⅰ亾dé卋堺 提交于 2019-11-26 14:20:32
问题 I think this is a pretty common problem. I've got a table user(id INT ...) and a table photo(id BIGINT, owner INT) . owner is a reference on user(id) . I'd like to add a constraint to the table photo that would prevent more than let's say 10 photos to enter the database for each users. What's the best way of writing this? Thx! 回答1: Quassnoi is right; a trigger would be the best way to achieve this. Here's the code: CREATE OR REPLACE FUNCTION enforce_photo_count() RETURNS trigger AS $$ DECLARE