primary-key

Remove Primary Key in MySQL

南笙酒味 提交于 2019-11-26 18:16:09
I have the following table schema which maps user_customers to permissions on a live MySQL database: mysql> describe user_customer_permission; +------------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_customer_id | int(11) | NO | PRI | NULL | | | permission_id | int(11) | NO | PRI | NULL | | +------------------+---------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) I would like to

Oracle (ORA-02270) : no matching unique or primary key for this column-list error

隐身守侯 提交于 2019-11-26 17:58:52
I have two tables, Table JOB and Table USER , here is the structure CREATE TABLE JOB ( ID NUMBER NOT NULL , USERID NUMBER, CONSTRAINT B_PK PRIMARY KEY ( ID ) ENABLE ); CREATE TABLE USER ( ID NUMBER NOT NULL , CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE ); Now, i want to add foreign key constraint to JOB referencing to USER table, as Alter Table JOB ADD CONSTRAINT FK_USERID FOREIGN KEY(USERID) REFERENCES USER(ID); this throws Oracle (ORA-02270) : no matching unique or primary key for this column-list error , doing some investigation it appears that we need to have either unique key or primary key

What are the design criteria for primary keys?

夙愿已清 提交于 2019-11-26 17:46:13
Choosing good primary keys, candidate keys and the foreign keys that use them is a vitally important database design task -- as much art as science. The design task has very specific design criteria. What are the criteria? The criteria for consideration of a primary key are: Uniqueness Irreducibility (no subset of the key uniquely identifies a row in the table) Simplicity (so that relational representation & manipulation can be simpler) Stability (should not be altered frequently) Familiarity (meaningful to the user) What is a Primary Key? The primary key is something that uniquely identifies

Python Pandas to_sql, how to create a table with a primary key?

ε祈祈猫儿з 提交于 2019-11-26 17:43:14
问题 I would like to create a MySQL table with Pandas' to_sql function which has a primary key (it is usually kind of good to have a primary key in a mysql table) as so: group_export.to_sql(con = db, name = config.table_group_export, if_exists = 'replace', flavor = 'mysql', index = False) but this creates a table without any primary key, (or even without any index). The documentation mentions the parameter 'index_label' which combined with the 'index' parameter could be used to create an index but

Can I use VARCHAR as the PRIMARY KEY?

本小妞迷上赌 提交于 2019-11-26 17:41:57
问题 I have a table for storing coupons/discounts, and I want to use the coupon_code column as the primary key, which is a VARCHAR . My rationale is that, each coupon will have a unique code, and the only commands I will be running are SELECT ... FROM ... WHERE coupon_code='..' I won't be doing any joins or indexing, and I don't see there ever being more than a few hundred entries in this table. It seems to me that this will be OK, but I don't know if there is anything I'm missing/not thinking

DynamoDB: When to use what PK type?

不想你离开。 提交于 2019-11-26 17:07:22
问题 I am trying to read up on best practices on DynamoDB. I saw that DynamoDB has two PK types: Hash Key Hash and Range Key From what I read, it appears the latter is like the former but supports sorting and indexing of a finite set of columns. So my question is why ever use only a hash key without a range key? Is it a viable choice only when the table is not searched? It'd also be great to have some general guidelines on when to use what key type. I've read several guides (including Amazon's own

SQL - many-to-many table primary key

点点圈 提交于 2019-11-26 17:01:47
This question comes up after reading a comment in this question: Database Design When you create a many-to-many table, should you create a composite primary key on the two foreign key columns, or create a auto-increment surrogate "ID" primary key, and just put indexes on your two FK columns (and maybe a unique constraint)? What are the implications on performance for inserting new records/re-indexing in each case? Basically, this: PartDevice ---------- PartID (PK/FK) DeviceID (PK/FK) vs. this: PartDevice ---------- ID (PK/auto-increment) PartID (FK) DeviceID (FK) The commenter says: making the

Mysql Innodb: Autoincrement non-Primary Key

狂风中的少年 提交于 2019-11-26 16:58:38
问题 Is it possible to auto-increment a non-Primary Key? Table "book_comments" book_id medium_int timestamp medium_int user_id medium_int vote_up small_int vote_down small_int comment text comment_id medium_int Primary key -> (book_id, timestamp, user_id) There will be no other indexes on this table. However, I would like to make the comment_id column autoincrement so that I can easily create another table: Table "book_comments_votes" comment_id (medium_int) user_id (medium_int) Primary key ->

MySQL: Determine Table's Primary Key Dynamically

这一生的挚爱 提交于 2019-11-26 16:49:47
问题 I'm, generating a SQL query like this in PHP: $sql = sprintf("UPDATE %s SET %s = %s WHERE %s = %s", ...); Since almost every part of this query is dynamic I need a way to determine the table's primary key dynamically, so that I'd have a query like this: $sql = sprintf("UPDATE %s SET %s=%s WHERE PRIMARY_KEY = %s", ...); Is there a MySQL keyword for a table's primary key, or a way to get it? I've used the information_schema DB before to find information like this, but it'd be nice if I didn't

Multi-Column Primary Key in MySQL 5

喜欢而已 提交于 2019-11-26 16:41:06
问题 I'm trying to learn how to use keys and to break the habit of necessarily having SERIAL type IDs for all rows in all my tables. At the same time, I'm also doing many-to-many relationships, and so requiring unique values on either column of the tables that coordinate the relationships would hamper that. How can I define a primary key on a table such that any given value can be repeated in any column, so long as the combination of values across all columns is never repeated exactly? 回答1: Quoted