unique-constraint

SQLite table constraint - unique on multiple columns

梦想与她 提交于 2019-11-26 05:17:02
问题 I can find syntax \"charts\" on this on the SQLite website, but no examples and my code is crashing. I have other tables with unique constraints on a single column, but I want to add a constraint to the table on two columns. This is what I have that is causing an SQLiteException with the message \"syntax error\". CREATE TABLE name (column defs) UNIQUE (col_name1, col_name2) ON CONFLICT REPLACE I\'m doing this based on the following: table-constraint To be clear, the documentation on the link

Can PostgreSQL have a uniqueness constraint on array elements?

大憨熊 提交于 2019-11-26 04:25:43
问题 I\'m trying to come up with a PostgreSQL schema for host data that\'s currently in an LDAP store. Part of that data is the list of hostnames a machine can have, and that attribute is generally the key that most people use to find the host records. One thing I\'d like to get out of moving this data to an RDBMS is the ability to set a uniqueness constraint on the hostname column so that duplicate hostnames can\'t be assigned. This would be easy if hosts could only have one name, but since they

How to delete duplicate entries?

徘徊边缘 提交于 2019-11-26 03:27:29
问题 I have to add a unique constraint to an existing table. This is fine except that the table has millions of rows already, and many of the rows violate the unique constraint I need to add. What is the fastest approach to removing the offending rows? I have an SQL statement which finds the duplicates and deletes them, but it is taking forever to run. Is there another way to solve this problem? Maybe backing up the table, then restoring after the constraint is added? 回答1: For example you could:

MySQL - Make an existing Field Unique

雨燕双飞 提交于 2019-11-26 02:06:26
问题 I have an already existing table with a field that should be unique but is not. I only know this because an entry was made into the table that had the same value as another, already existing, entry and this caused problems. How do I make this field only accept unique values? 回答1: ALTER IGNORE TABLE mytbl ADD UNIQUE (columnName); For MySQL 5.7.4 or later: ALTER TABLE mytbl ADD UNIQUE (columnName); As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error. So

How do I specify unique constraint for multiple columns in MySQL?

一世执手 提交于 2019-11-25 21:43:50
问题 I have a table: table votes ( id, user, email, address, primary key(id), ); Now I want to make the columns user, email, address unique (together). How do I do this in MySql? Of course the example is just... an example. So please don\'t worry about the semantics. 回答1: ALTER TABLE `votes` ADD UNIQUE `unique_index`(`user`, `email`, `address`); 回答2: I have a MySQL table: CREATE TABLE `content_html` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_box_elements` int(11) DEFAULT NULL, `id_router` int(11)