unique-constraint

How to do multiple column unique-constraint in ormlite ( SQLite )

牧云@^-^@ 提交于 2019-12-05 02:44:44
I'm using ormlite for Android and I'm trying to get a multiple column unique-constraint. As of now i'm only able to get a unique constraint on indiviudal columns like this: CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL UNIQUE , `store_item_id` INTEGER NOT NULL UNIQUE , `_id` INTEGER PRIMARY KEY AUTOINCREMENT ); and what I want is CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL , `store_item_id` INTEGER NOT NULL , `_id` INTEGER PRIMARY KEY AUTOINCREMENT, UNIQUE( `store_group_id`, `store_item_id` ); In my model I've been using the following annotations for

Multi-Column Unique Constraint with web2py

房东的猫 提交于 2019-12-05 02:21:11
It is possible to mark a particular column as unique=true. What is the most correct way to handle multi-column unique constraints in web2py? For example, say I have an exchange rate table. It could have columns from-currency, to-currency and the exchange rate. It would not make sense to have two rows with the same from and to currencies. What would be the most elegant or correct way to make the from/to combination unique? Assuming the data will be entered via a form, you could use a form validator, like this: db.define_table('rates', Field('from_currency'), Field('to_currency')) db.rates.to

How to specify that a combination of columns should be a unique constraint using annotations?

烈酒焚心 提交于 2019-12-05 00:36:11
I want to make sure that all rows in my table have a unique combination of two fields, and I want to specify this using annotations in my entity class. I have tried using a combination of @Table and @UniqueConstraint but apparently I'm doing it wrong, in that I can only seem to specify that the separate columns should be unique (I can already specify that using the @Column's unique property) rather than a combination of columns. For example I want a table which has fields A and B to contain only rows which have a unique combination of A and B. Neither field/column needs to be unique, it's the

How to enforce unique constraint with LINQ to SQL

安稳与你 提交于 2019-12-04 20:03:38
I'd like to enforce a unique constraint on two columns with LINQ to SQL. I have got a constraint configured on a SQL table, but is there a way to use it with LINQ to SQL? Unique constraint is applied to two columns, both of which are foreign keys. Thank you Edit: I could catch exception, that's if a very specific exception gets thrown. Alternative is to check state of the table before running any updates/inserts. All seems to be like too much work for a very simple task. In my opinion, L2S should not be doing the actual enforcement of this. Your database should be doing it via a unique

ORA-00001: unique constraint primary key violated

青春壹個敷衍的年華 提交于 2019-12-04 19:33:30
DELETE from dbo.T_LIAV_AGENT_STATE_APPROVAL SAP WHERE EXISTS (SELECT UNIQUE 1 FROM MCS_SYNC_STATE_APPR APP inner join MCS_SYNC_NAME SN on SN.SE_NAME_ID = APP.SE_NAME_ID and SN.ACTION in('U','S') Where APP.SE_name_id = SAP.AV_NAME_ID and APP.SYNC_INSTANCE_ID = param_inst_ID); COMMIT; INSERT INTO dbo.T_LIAV_AGENT_STATE_APPROVAL SELECT UNIQUE APP.SE_NAME_ID AS AV_NAME_ID, APP.STATE AS AV_STATE, APP.APPROVAL_TYPE AS AV_APPROVAL_TYPE, APP.START_DATE AS AV_START_DATE, APP.END_DATE AS AV_END_DATE, APP.APPOINTED AS AV_APPOINTED, APP.RENEWAL_DATE AS AV_RENEWAL_DATE, APP.LICENSE AS AV_LICENSE, COMPANY

Is there a good way to do this in SQL?

此生再无相见时 提交于 2019-12-04 10:21:06
I am trying to solve the following problem entirely in SQL (ANSI or TSQL, in Sybase ASE 12), without relying on cursors or loop-based row-by-row processing. NOTE: I already created a solution that accomplishes the same goal in application layer (therefore please refrain from "answering" with "don't do this in SQL"), but as a matter of principle (and hopefully improved performance) I would like to know if there is an efficient (e.g. no cursors) pure SQL solution. Setup : I have a table T with the following 3 columns (all NOT NULL): ---- Table T ----------------------------- | item | tag | value

Hibernate / JPA many to many relationship through a join table and a composite key, Unique Constraint issue

南楼画角 提交于 2019-12-04 08:18:00
So I asked this question yesterday, but the goal posts have changed and the question is different: Hibernate / JPA Collection of Elements with Many to Many relationship? I want to know if it's possible to create entities that will model my required relationship so that Hibernate will create my schema when I fire up my application. The relationship I want looks like this: 1 http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/417593_10150594114269218_505554217_8657377_1475865815_n.jpg The thing is that the Join table can actually contain rows that don't link to any Elements. The structure represents

Naming convention for unique constraint

不羁的心 提交于 2019-12-04 07:21:33
问题 Naming conventions are important, and primary key and foreign key have commonly used and obvious conventions ( PK_Table and FK_Table_ReferencedTable , respectively). The IX_Table_Column naming for indexes is also fairly standard. What about the UNIQUE constraint? Is there a commonly accepted naming convention for this constraint? I've seen UK_TableName_Column , UQ_TableName_Column , and someone recommending AX_TableName_Column - I don't know where that comes from. I've typically used UQ but I

PostgreSQL constraint, that gets checked on commit and not earlier [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 05:26:15
问题 This question already has answers here : Constraint defined DEFERRABLE INITIALLY IMMEDIATE is still DEFERRED? (2 answers) Closed last year . Is it possible to create to create a unique index or other kind of constraint in PostgreSQL, that would be checked on transaction COMMIT and not a millisecond earlier? I need an index for a pair of (record_id, ordering), so I make sure that inside a given record_id only one and no more than one records has the same ordering. Where's the problem? Well,

For a composite foreign key, is a/why is a composite UNIQUE constraint in the referenced table required for a column combination with a primary key?

允我心安 提交于 2019-12-04 05:22:07
问题 I have a question regarding explicitly defining of the uniqueness of something. This relates to the creation of a composite foreign key. I've created an example below to try and make my question as clear as possible (I've included some data inserts for ease of testing). Each entry for [Table1] must have a unique [Name] . CREATE TABLE [Table1] ( [ID] INT IDENTITY NOT NULL PRIMARY KEY, [Name] NVARCHAR(255) UNIQUE NOT NULL CHECK(LTRIM(RTRIM([Name])) <> '') ); INSERT INTO [Table1]([Name]) VALUES