unique-constraint

How do I ALTER a PostgreSQL table and make a column unique?

吃可爱长大的小学妹 提交于 2019-11-27 10:53:55
I have a table in PostgreSQL where the schema looks like this: CREATE TABLE "foo_table" ( "id" serial NOT NULL PRIMARY KEY, "permalink" varchar(200) NOT NULL, "text" varchar(512) NOT NULL, "timestamp" timestamp with time zone NOT NULL ) Now I want to make the permalink unique across the table by ALTER-ing the table. Can anybody help me with this? TIA Baishampayan Ghose I figured it out from the PostgreSQL docs, the exact syntax is: ALTER TABLE the_table ADD CONSTRAINT constraint_name UNIQUE (thecolumn); Thanks Fred . Clint Pachl Or, have the DB automatically assign a constraint name using:

A Queue that ensure uniqueness of the elements?

℡╲_俬逩灬. 提交于 2019-11-27 10:40:51
问题 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

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

。_饼干妹妹 提交于 2019-11-27 09:44:03
问题 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

unique property in Firebase

空扰寡人 提交于 2019-11-27 08:50:31
问题 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. 回答1: 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

Shift (update) unique column values in PostgreSQL

99封情书 提交于 2019-11-27 08:03:20
问题 Using MS SQL Server, the following works fine: CREATE TABLE #temptable(mykey int primary key) INSERT INTO #temptable VALUES (1) INSERT INTO #temptable VALUES (2) UPDATE #temptable SET mykey=mykey+1 However, using PostgreSQL, the following fails: CREATE TABLE pg_temp.tbl_test(testkey integer primary key) INSERT INTO pg_temp.tbl_test VALUES (1) INSERT INTO pg_temp.tbl_test VALUES (2) UPDATE pg_temp.tbl_test SET testkey=testkey+1 ERROR: duplicate key value violates unique constraint "tbl_test

Unique Key Violation in SQL Server - Is it safe to assume Error 2627?

萝らか妹 提交于 2019-11-27 04:09:12
I need to catch violation of UNIQUE constraints in a special way by a C# application I am developing. Is it safe to assume that Error 2627 will always correspond to a violation of this kind, so that I can use if (ThisSqlException.Number == 2627) { // Handle unique constraint violation. } else { // Handle the remaing errors. } ? 2627 is unique constraint (includes primary key), 2601 is unique index SELECT * FROM sys.messages WHERE text like '%duplicate%' and text like '%key%' and language_id = 1033 Here is a handy extension method I wrote to find these: public static bool IsUniqueKeyViolation

SQL unique varchar case sensitivity question

你说的曾经没有我的故事 提交于 2019-11-27 03:47:32
I'm trying to populate a SQL table with a list of words. The table itself it pretty simple: CREATE TABLE WORDS( ID BIGINT AUTO_INCREMENT, WORD VARCHAR(128) NOT NULL UNIQUE, PRIMARY KEY(ID) ); The problem I'm running into is this: when I do the following inserts back to back INSERT INTO WORDS(WORD) VALUES('Seth'); INSERT INTO WORDS(WORD) VALUES('seth'); The second insert fails with a constraint violation ("Duplicate entry 'seth' for key 'WORD'"). How can I get the UNIQUE constraint on WORD to be case sensitive? Bill Brasky Looks like mysql is case insensitive by default : You probably need to

Using unique constraint on Hibernate JPA2

你离开我真会死。 提交于 2019-11-27 03:13:49
问题 How can I implement my unique constraints on the hibernate POJO's? assuming the database doesn't contain any. I have seen the unique attribute in @Column() annotation but I couldn't get it to work? What if I want to apply this constraint to more than one column? 回答1: Bascially, you cannot implement unique constraint without database support. @UniqueConstraint and unique attribute of @Column are instructions for schema generation tool to generate the corresponsing constraints, they don't

Does Entity Framework 5 support unique constraints?

℡╲_俬逩灬. 提交于 2019-11-27 03:09:28
问题 Wondering if Entity Framework 5 supports unique constraints on entity properties? If so, how can I specify that a property should be unique? 回答1: No, it doesn't. There were plans in the past to include a unique constraint feature in EF 5.0: http://blogs.msdn.com/b/efdesign/archive/2011/03/09/unique-constraints-in-the-entity-framework.aspx But you can see that there is an update on top of the post: Update: this feature has been postponed and will not be included in Entity Framework 5. You can

How to drop a unique constraint from table column?

若如初见. 提交于 2019-11-27 02:35:53
问题 I have a table 'users' with 'login' column defined as: [login] VARCHAR(50) UNIQUE NOT NULL Now I want to remove this unique constraint/index using SQL script. I found its name UQ_ users _7D78A4E7 in my local database but I suppose it has a different name on another database. What is the best way to drop this unique constraint? Or at least any... Thanks. 回答1: SKINDER, your code does not use column name. Correct script is: declare @table_name nvarchar(256) declare @col_name nvarchar(256)