constraints

Entity framework Code First One-to-One relationship

无人久伴 提交于 2019-11-30 08:54:36
I have two entities which I want to be connected 1:1 relationship. User is principal and UserActivation is dependent, but I have no idea how that works. public class User { [Key] public Guid Id { get; set; } public string Name { get; set; } public string Lastname { get; set; } public string Username { get; set; } public virtual UserActivation UserActivation { get; set; } } public class UserActivation { [Key] public Guid Id { get; set; } public Guid UserId { get; set; } public bool Active { get; set; } public virtual User User { get; set; } } I have tried to remove 'virtual' keyword, have tried

Why can I create a table with PRIMARY KEY on a nullable column?

柔情痞子 提交于 2019-11-30 08:53:31
问题 The following code creates a table without raising any errors: CREATE TABLE test( ID INTEGER NULL, CONSTRAINT PK_test PRIMARY KEY(ID) ) Note that I cannot insert a NULL, as expected: INSERT INTO test VALUES(1),(NULL) ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null). ********** Error ********** ERROR: null value in column "id" violates not-null constraint SQL state: 23502 Detail: Failing row contains (null). Why can I create a table with a self

Solr - Block join Parent query with many Children constraints

丶灬走出姿态 提交于 2019-11-30 07:45:56
The question is applied for the following nested documents: <doc> <field name="id">1</field> <field name="title">Solr has block join support</field> <field name="content_type">parentDocument</field> <doc> <field name="id">11</field> <field name="type">comment</field> <field name="comments">SolrCloud supports it too!</field> </doc> <doc> <field name="id">12</field> <field name="type">publisher</field> <field name="address">England</field> .... </doc> </doc> .... My question is, how to write the Block Join Parent Query which allows to have constraints on multiple nested children documents? I did

How to do multiple column UniqueConstraint in hbm?

对着背影说爱祢 提交于 2019-11-30 07:19:49
问题 Working on some legacy hibernate code. How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations? @Table(name="users", uniqueConstraints = { @UniqueConstraint(columnNames={"username", "client"}), @UniqueConstraint(columnNames={"email", "client"}) }) public class User implements Serializable { private static final long serialVersionUID = 1L; @Id private int id; private String username; private String email; private Client client; } 回答1: Use the properties tag:

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

对着背影说爱祢 提交于 2019-11-30 06:44:42
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. 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 are changed to nulls and so not indexed. This is a kludgy hack, but if the column allows NULLs, then you could

Can you replace or update a SQL constraint?

时光毁灭记忆、已成空白 提交于 2019-11-30 06:33:28
I have written the following constraint for a column I've called 'grade': CONSTRAINT gradeRule CHECK grade IN (‘easy’, ‘moderate’, ‘difficult’), Is it possible to later update the gradeRule to have different values? For example, 'moderate' and 'difficult' could be changed to 'medium' and 'hard'. Thanks You could drop the existing constraint, and add the new constraint with the NOCHECK option. This would allow you to add the constraint even though data in the table violates the constraint. The problem with doing this though would be that you wouldn't be able to update existing records without

Xcode 8 UIButtons with constraints not showing up

孤人 提交于 2019-11-30 06:32:33
问题 Everything used to work great until yesterday I updated Xcode to version 8. If I don't use any constraints, I can see the buttons but when I apply constraint(s) to the buttons they disappear, no matter what or how many constraints (height, vertical spacing, trailing etc...) I apply. When I tap buttons, they act normal (events are always sent so I assume they are actually located there(?)). I tried changing text color, background color, (even adding a new UIButton) but ended with no luck. I

T-SQL: How do I create a unique key that is case sensitive?

旧巷老猫 提交于 2019-11-30 06:29:03
问题 How do I create a unique constraint on a varchar field that is case sensitive (SQL Server 2005)? Currently my constraint looks like this: alter table MyTable add constraint UK_MyTable_MyUniqueKey unique nonclustered (MyCol) When I try to insert the following two values, I get a "Violation of UNIQUE KEY constraint..." error. insert into MyTable (MyCol) values ('ABC') insert into MyTable (MyCol) values ('abc') --causes a violation of UNIQUE KEY constraint 'UK_MyTable_MyUnqiueKey' I would like

Drop All constraints in a Table

扶醉桌前 提交于 2019-11-30 06:24:51
问题 Am trying to write script for removing Constraints. I have the below function to select the Constarints in my DataBase SELECT name FROM sys.foreign_keys And I have written alter scripts using the above scripts SELECT 'ALTER TABLE ' + OBJECT_NAME(parent_object_id) + ' DROP CONSTRAINT ' + name FROM sys.foreign_keys Using the above query how can I execute these constraints ? I can use DROP DATABASE DBName . But am just trying to drop tables by dropping Constraints. is it possible without going

Conditional SQLite check constraint?

我只是一个虾纸丫 提交于 2019-11-30 06:13:05
I have a table defined by the following SQL: CREATE TABLE test ( id integer PRIMARY KEY NOT NULL UNIQUE, status text NOT NULL, enddate date, /* Checks */ CHECK (status IN ("Current", "Complete")) ); I'd like to add a constraint that requires enddate to be non-null if the status is "Complete". Is this possible? I am using SQLite v3.6.16. How about: CHECK (status = "Current" or (status = "Complete" and enddate is not null)) Ensarija CREATE TABLE test ( id integer PRIMARY KEY, status text NOT NULL CHECK (status IN ('Current', 'Complete')), enddate date NOT NULL ); This will work in SQLite, with