unique-constraint

How to give a unique constraint to a combination of columns in Oracle?

霸气de小男生 提交于 2019-11-29 02:53:12
I have a Table with 4 Columns Each Column will be A,B,C,D Column A is the Primary key. Column B has unique name constraint. Now I want to remove the unique constraint for column B and give a unique constraint by combining the columns B, C and D. So the table will allow only one row with a particular value in columns B,C and D. How can I give this type of a constraint? I tried giving the composite unique key like : ALTER TABLE TABLENAME ADD CONSTRAINT CONSTRAINT_NAME UNIQUE (COLUMN_B, COLUMN_C, COLUMN_D) But it is checking whether any one of the constraint is present rather than checking for

Unique Constraint vs Unique Index

倖福魔咒の 提交于 2019-11-28 22:01:28
问题 I’m interested in learning which technique developers prefer to use to enforce uniqueness in SQL Server: UNIQUE CONSTRAINT or UNIQUE INDEX. Given that there is little difference in the physical implementation of each, how do you decide which is best? Are there reasons other than performance to evaluate the best solution? Are there database management advantages to one or the other? 回答1: This MSDN article comparing the two is for SQL Server 2000: http://msdn.microsoft.com/en-us/library

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

巧了我就是萌 提交于 2019-11-28 21:22:24
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 constraint 'Unique_GiftId'. Cannot insert duplicate key in object 'dbo.Donations'.\r\nThe statement has been

Grails domain class: unique constraint for multiple columns

偶尔善良 提交于 2019-11-28 20:03:48
Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId , thus there must be a unique contraint on two columns. How to express this in the constraints definition? userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on the username. So, for example if you wanted to make userName unique within a countryId and provinceId it

Unique index or unique key?

南楼画角 提交于 2019-11-28 19:07:48
What is the diffrence between a unique index and a unique key? Dustin Laine The unique piece is not where the difference lies. The index and key are not the same thing, and are not comparable. A key is a data column, or several columns, that are forced to be unique with a constraint, either primary key or explicitly defined unique constraint. Whereas an index is a structure for storing data location for faster retrieval. From the docs: Unique Index Creates a unique index on a table or view. A unique index is one in which no two rows are permitted to have the same index key value. A clustered

A Queue that ensure uniqueness of the elements?

情到浓时终转凉″ 提交于 2019-11-28 17:43:19
I'm looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique. (all further insertion will have no effect) It's that possible, or will I have to do it by hand? For now I'm using a Queue, with a LinkedList implementation, and I check the uniqueness before insertion. ( I use a side Map for doing this, add / remove element from the side map before / after the queu ). I don't like it too much. Any input is welcome. If it's not in the java.util package, then maybe it's a bad idea? How about

How can I create a unique constraint on my column (SQL Server 2008 R2)?

若如初见. 提交于 2019-11-28 17:41:41
I have SQL Server 2008 R2 and I want to set a unique column. There seems to be two ways to do this: "unique index" and "unique constraint". They are not much different from what I understand, although unique constraint is recommended by most, because you also get an index automatically. How do I create a unique constraint? ALTER TABLE Customer ADD CONSTRAINT U_Name UNIQUE(Name) Is there a way to create a unique constraint through the SQL Server Management Studio? To create these constraints through the GUI you need the "indexes and keys" dialogue not the check constraints one. But in your case

MySQL delete multiple rows in one query conditions unique to each row

不问归期 提交于 2019-11-28 16:29:11
So I know in MySQL it's possible to insert multiple rows in one query like so: INSERT INTO table (col1,col2) VALUES (1,2),(3,4),(5,6) I would like to delete multiple rows in a similar way. I know it's possible to delete multiple rows based on the exact same conditions for each row, i.e. DELETE FROM table WHERE col1='4' and col2='5' or DELETE FROM table WHERE col1 IN (1,2,3,4,5) However, what if I wanted to delete multiple rows in one query, with each row having a set of conditions unique to itself? Something like this would be what I am looking for: DELETE FROM table WHERE (col1,col2) IN (1,2)

unique property in Firebase

与世无争的帅哥 提交于 2019-11-28 14:43:35
I have an IOS app which contains categories. My storage on Firebase looks like this: -root -Categories -key - color: - name: - sum: -Expenses -key -amount: -category: -date: -description: -initiator: -name: User must not add a category twice. I want to make category name unique. Is it possible to do in Firebase? Thanks in advance. Frank van Puffelen There is no way to ensure unique values in the Firebase Database. But on the other hand keys are always unique within their context. You can make use of this to model your data in such a way that it guarantees uniqueness of the property you want.

UNIQUE constraint controlled by a bit column

妖精的绣舞 提交于 2019-11-28 12:18:33
I have a table, something like FieldsOnForms( FieldID int (FK_Fields) FormID int (FK_Forms) isDeleted bit ) The pair (FieldID,FormID) should be unique, BUT only if the row is not deleted (isDeleted=0). Is it possible to define such a constraint in SQLServer 2008? (without using triggers) P.S. Setting (FieldID, FormID, isDeleted) to be unique adds the possibility to mark one row as deleted, but i would like to have the chance to set n rows (per FieldID,FormID) to isDeleted = 1, and to have only one with isDeleted = 0 You can have a unique index , using the SQL Server 2008 filtered indexes