unique-constraint

mysql combined unique keys

為{幸葍}努か 提交于 2019-12-18 13:00:53
问题 Is there way in MySQL to have two unique keys and connect them somehow? for example if i have the following table and 'title'and 'store' are a unique keys id | category | title | price | store 1 | outdoors | fishing rod | 59.99 | wal-mart 2 | auto | Penzoil Oil | 9.99 | target and i try to insert the following record. This new record would be ignored because the title is "fishing rod" AND the store is 'wal-mart' and there is an existing record with that title and store | outdoors | fishing

Add a unique constraint of a sql table as foreign key reference to an another sql table

佐手、 提交于 2019-12-18 08:46:24
问题 how to add a unique constraint of a sql table as foreign key reference to an another sql table in sql server 2005 回答1: In order to add FK constraint (in child table to parent table) you have to add unique constraint to parent table columns of relationship. All the rest is optional or has nothing to do with FK: no obligatory need of any primary key no need of uniqueness in child table colums(s) The parent table (in such FK relation) is frequently called (including by SSMS) as Primary Key table

How can I add constraints to an ADO.NET Entity?

╄→гoц情女王★ 提交于 2019-12-18 05:55:54
问题 I know how to mark a group of fields as primary key in ADO.NET entities but i haven't found a way to declare unique constraints or check constraints. Is this feature missing on the designer or on the framework? 回答1: Support for unique keys/constraints does not exist in ADO.NET Entities in v4.0, see the answer to "one-to-one association on a foreign key with unique constraint", where Diego B Vega says: I know for sure we haven't added support for unique keys other than primary keys in 4.0. He

duplicate null value violation on UNIQUE KEY constraint in Mssql

故事扮演 提交于 2019-12-18 04:52:43
问题 MS SQL Server does not ignore the null value and considers it as violation for the UNIQUE KEY constraint but what I know is that the UNIQUE KEY differ from the primary key where it accepts the null value. Violation of UNIQUE KEY constraint 'AK_UserName'. Cannot insert duplicate key in object 'dbo.users'. The duplicate key value is (<NULL>). The statement has been terminated. Can anyone help me to solve this problem? 回答1: you can create a unique index that ignores null values like this CREATE

Entity Framework: How to properly handle exceptions that occur due to SQL constraints

我是研究僧i 提交于 2019-12-17 23:39:56
问题 I use Entity Framework to access my SQL data. I have some constraints in the database schema and I wonder how to handle exceptions that are caused by these constraints. As example, I get the following exception in a case where two users try to add an (almost) identical entity to the DB concurrently. System.Data.UpdateException "An error occurred while updating the entries. See the InnerException for details." (inner exception) System.Data.SqlClient.SqlException "Violation of UNIQUE KEY

How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use?

大憨熊 提交于 2019-12-17 02:38:49
问题 I've been trying to sort out the relationship between unique and index in Postgres after reading the docs on index uniqueness being an implementation detail: The preferred way to add a unique constraint to a table is ALTER TABLE ... ADD CONSTRAINT. The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly. One should, however, be aware that there's no need to manually create indexes on unique columns; doing so would just

Unique Constraint in Entity Framework Code First

爱⌒轻易说出口 提交于 2019-12-17 02:07:30
问题 Question Is it possible to define a unique constraint on a property using either the fluent syntax or an attribute? If not, what are the workarounds? I have a user class with a primary key, but I would like to make sure the email address is also unique. Is this possible without editing the database directly? Solution (based on Matt's answer) public class MyContext : DbContext { public DbSet<User> Users { get; set; } public override int SaveChanges() { foreach (var item in ChangeTracker

MySQL UNIQUE Constraint multiple columns condition

对着背影说爱祢 提交于 2019-12-13 21:49:01
问题 Well, i have a table with 4 columns( id , event_id , group_id , isbn ), where id is PK, event_id and group_id are FK's, and my problem is: I need the isbn number to be unique for each event_id , let me give you some examples of some rows that should be possible and some that should not: id | event_id | group_id | isbn (1,1,1,123) ok (2,1,2,123) ok (3,1,4,123) ok (4,1,7,1234) ok (5,2,8,123) NOT OK, the 'isbn' must be unique for event_id('123' was already used in the first row with event_id = 1

Exception: Could not synchronize database state with session

若如初见. 提交于 2019-12-13 19:09:33
问题 I have an web application developed on spring and hibernate 3.0 and deployed on apache tomcat 6. I am getting below error when I am trying to insert the data to the one of the table ('CAR_ATTRIBUTE' table). [CAR] [2010-12-12 13:41:30,651] ERROR [http-80-2] AbstractFlushingEventListener.performExecutions(301) | Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: could not insert: [com.test.model.CarAttribute] at org.hibernate.exception

define unique constraint based on multiple elements

半世苍凉 提交于 2019-12-13 14:31:55
问题 Here is a simplified version of my XML: <Invoice> <DataRow> <Group>ZB</Group> <Specie>M</Specie> <Length>360</Length> </DataRow> <DataRow> <Group>ZB</Group> <Specie>M</Specie> <Length>360</Length> </DataRow> </Invoice> I want this XML to be not validated, because the values of Group/Specie/Length are the same. So I want to add an unique constraint in my XSD file. I've got this for the unique constraint: <xs:unique name="specieSizeGroupLengthAssortment"> <xs:selector xpath="Invoice/DataRow"/>