unique-constraint

Find or insert based on unique key with Hibernate

折月煮酒 提交于 2019-12-03 03:47:30
问题 I'm trying to write a method that will return a Hibernate object based on a unique but non-primary key. If the entity already exists in the database I want to return it, but if it doesn't I want to create a new instance and save it before returning. UPDATE: Let me clarify that the application I'm writing this for is basically a batch processor of input files. The system needs to read a file line by line and insert records into the db. The file format is basically a denormalized view of

Can I add a UNIQUE constraint to a PostgreSQL table, after it's already created?

好久不见. 提交于 2019-12-03 00:55:52
问题 I have the following table: tickername | tickerbbname | tickertype ------------+---------------+------------ USDZAR | USDZAR Curncy | C EURCZK | EURCZK Curncy | C EURPLN | EURPLN Curncy | C USDBRL | USDBRL Curncy | C USDTRY | USDTRY Curncy | C EURHUF | EURHUF Curncy | C USDRUB | USDRUB Curncy | C I don't want there to ever be more than one column for any given tickername / tickerbbname pair. I've already created the table and have lots of data in it (which I have already ensured meets the

Unique constraint on multiple columns

人盡茶涼 提交于 2019-12-02 20:10:05
I am using an oracle table and have created a unique constraint over four columns. Can these columns within the constraint have NULL in them? you can have NULLs in your columns unless the columns are specified NOT NULL. You will be able to store only one instance of NULLs however (no two sets of same columns will be allowed unless all columns are NULL) : SQL> CREATE TABLE t (id1 NUMBER, id2 NUMBER); Table created SQL> ALTER TABLE t ADD CONSTRAINT u_t UNIQUE (id1, id2); Table altered SQL> INSERT INTO t VALUES (1, NULL); 1 row inserted SQL> INSERT INTO t VALUES (1, NULL); INSERT INTO t VALUES (1

Creating UNIQUE constraint on multiple columns in MySQL Workbench EER diagram

被刻印的时光 ゝ 提交于 2019-12-02 17:25:59
In MySQL Workbench's EER diagram, there is a checkbox to make each column in a table unique, not null, primary key etc. However, I would like to have a UNIQUE constraint on multiple columns. Is it possible to add it in in MySQL Workbench's EER diagram? EDIT: Ok, I realised the unique checkbox, creates a UNIQUE INDEX, and not a UNIQUE CONSTRAINT In the Alter Table dialog of MySQL Workbench: Go to Indexes tab. Double-click on a blank row to create a new index. Choose 'UNIQUE' as the index type. Check the columns that you want to be unique together. There's some discussion as to whether this is

Can I add a UNIQUE constraint to a PostgreSQL table, after it's already created?

不打扰是莪最后的温柔 提交于 2019-12-02 14:19:47
I have the following table: tickername | tickerbbname | tickertype ------------+---------------+------------ USDZAR | USDZAR Curncy | C EURCZK | EURCZK Curncy | C EURPLN | EURPLN Curncy | C USDBRL | USDBRL Curncy | C USDTRY | USDTRY Curncy | C EURHUF | EURHUF Curncy | C USDRUB | USDRUB Curncy | C I don't want there to ever be more than one column for any given tickername / tickerbbname pair. I've already created the table and have lots of data in it (which I have already ensured meets the unique criteria). As it gets larger, though, room for error creeps in. Is there any way to add a UNIQUE

Naming convention for unique constraint

北城以北 提交于 2019-12-02 13:52:56
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 don't particularly like it, and I do not enjoy having to defend my choice of using it against a UK

Autoincrement, but omit existing values in the column

妖精的绣舞 提交于 2019-12-02 10:48:05
问题 I have a table: create table DB.t1 (id SERIAL,name varchar(255)); and insert some data: insert into DB.t1 (name) values ('name1'); insert into DB.t1 (id,name) values (5,'name2'); insert into DB.t1 (name) values ('name3'); insert into DB.t1 (name) values ('name4'); insert into DB.t1 (name) values ('name5'); insert into DB.t1 (name) values ('name6'); insert into DB.t1 (name) values ('name7'); select * from DB.t1; Then I can see: 1 name1 5 name2 2 name3 3 name4 4 name5 5 name6 -- how to make

Unique Contrains in Vertica DB

半世苍凉 提交于 2019-12-02 10:38:07
问题 Disclaimer: My DB knowledge comes mostly from Mysql so I might misunderstand some things in vertica... I would like to know if there exist a technique of inserting/updating values in vertica while enforcing unique constrains across multiple sessions. Let's assume I have a table: 'id', 'unique_field', 'some_filed' And there is a unique constraint on unique_field. My understanding is that in vertica one first needs to do an insert and then do ANALYZE_CONSTRAINTS to verify if the constraint was

MySQL unique index by multiple fields

。_饼干妹妹 提交于 2019-12-02 09:35:59
问题 We have a special kind of table in our DB that stores the history of its changes in itself. So called "self-archived" table: CREAT TABLE coverages ( id INT, # primary key, auto-increment subscriber_id INT, current CHAR, # - could be "C" or "H". record_version INT, # etc. ); It stores "coverages" of our subscribers. Field "current" indicates if this is a current/original record ("C") or history record ("H"). We could only have one current "C" coverage for the given subscriber, but we can't

How do I enforce set-like uniqueness between multiple columns? [duplicate]

与世无争的帅哥 提交于 2019-12-02 08:33:44
问题 This question already has answers here : sql unique constraint on a 2 columns combination (3 answers) Closed 5 years ago . I'm not sure I've phrased the question correctly, so I'll try a longer explanation. I have this kind of table: CREATE TABLE x (a int, b int); I want to consider the pair (a,b) to be identical to (b,a), and to disallow insertion of duplicates. If PostgreSQL had a set data type, I might declare the table like this: CREATE TABLE x ( ab set, UNIQUE (ab) ); But it doesn't, so