composite-primary-key

Foreign key constraint is incorrectly formed with Composite Keys

烂漫一生 提交于 2019-12-11 17:22:48
问题 I have a table "theaters". In which (theater_name,area_name,station) are composite key.And in the table "cubelists" I have columns (thtr_name,area,stn) which are to be referred to (theater_name,area_name,station) of table "theaters". The problem here is the combination of the columns - (theater_name,area_name,station) in table "theaters" is unique as it is a composite key. But each column separately is not unique. Then how can I refer these columns from table "cubelists"? Schema::create(

Autogenerate composite key in SQLite

烂漫一生 提交于 2019-12-11 13:50:56
问题 I have a composite primary key {shop_id, product_id} for SQLite Now, I want an auto-increment value for product_id which resets to 1 if shop id is changed. Basically, I want auto-generated composite key e.g. Shop ID Product Id 1 1 1 2 1 3 2 1 2 2 3 1 Can I achieve this with auto-increment? How? 回答1: Normal Sqlite tables are B*-trees that use a 64-bit integer as their key. This is called the rowid. When inserting a row, if a value is not explicitly given for this, one is generated. An INTEGER

referencing part of the composite primary key

余生颓废 提交于 2019-12-11 11:07:46
问题 I have problems with setting the reference on database table. I have following structure: CREATE TABLE club( id INTEGER NOT NULL, name_short VARCHAR(30), name_full VARCHAR(70) NOT NULL ); CREATE UNIQUE INDEX club_uix ON club(id); ALTER TABLE club ADD CONSTRAINT club_pk PRIMARY KEY (id); CREATE TABLE team( id INTEGER NOT NULL, club_id INTEGER NOT NULL, team_name VARCHAR(30) ); CREATE UNIQUE INDEX team_uix ON team(id, club_id); ALTER TABLE team ADD CONSTRAINT team_pk PRIMARY KEY (id, club_id);

Django Custom primary key

房东的猫 提交于 2019-12-11 04:36:44
问题 When I inspect the Trac database I get: class TicketChange(models.Model): ticket = models.IntegerField() time = models.BigIntegerField() author = models.TextField(blank=True) field = models.TextField() oldvalue = models.TextField(blank=True) newvalue = models.TextField(blank=True) class Meta: managed = False db_table = 'ticket_change' With not primary key: >>> TicketChange.objects.all() DatabaseError: column ticket_change.id does not exist LINE 1: SELECT "ticket_change"."id", "ticket_change".

How to migrate from a composite primary key to a single attribute key in SQL?

泪湿孤枕 提交于 2019-12-11 03:40:40
问题 I would like to migrate a table that uses a composite primary key to a unique primary key. My table is as follow: CREATE TABLE REGM ( LNG_CD VARCHAR2(2 BYTE) NOT NULL ENABLE, REG_NRI NUMBER(10,0) NOT NULL ENABLE, ... CONSTRAINT PK_REGM PRIMARY KEY (LNG_CD, REG_NRI) ENABLE, ); The table REGM uses LNG_CD and REG_NRI as a composite primary key. I would like to uses a primary key name REGM_PK instead, but still uses LNG_CD and REG_NRI as foreign key. So far, this is my approach: 1 - Drop the

MyISAM vs InnoDB for quick inserts and a composite unique key

你离开我真会死。 提交于 2019-12-10 22:32:48
问题 Context: I'm creating a multi-threaded application that will be inserting/updating rows very frequently. Originally I had the following table: #TABLE 1 CREATE TABLE `example` ( `id` BIGINT(20) NOT NULL, `state` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`, `state`)) ENGINE = MyISAM; However after doing some research I found that MySQL uses table-level locking for MyISAM tables permitting only one session to update those tables at a time (source). Not good for a multi-threaded application making

Composite primary keys in sqlite

六月ゝ 毕业季﹏ 提交于 2019-12-10 19:09:32
问题 PRIMARY KEY(col1, col2) creates a index called "sqlite_autoindex_mytable_1". I saw it in "SQlite Expert". And in the "fields to index" box it shows both col1 and col2. In this post: https://dba.stackexchange.com/a/14260 it says that I have to create separate indexes for col2 if I want to use col2 in JOIN queries without col1. So I would need to add: CREATE INDEX "myidx" ON "mytable"("col2"); If I have this query: SELECT t2.* FROM mytable as t1 INNER JOIN mytable2 as t2 ON t1.col2 = t2.id do I

Doctrine 2 one-to-one via composite key

狂风中的少年 提交于 2019-12-10 15:43:48
问题 I am trying to set up a relationship as shown below. Each car can have one review. A car has a primary key on 2 columns. Review is referenced back to the car via the composite primary key. Simple, in theory. class Car { /** * @ORM\Id * @ORM\Column(type="string") */ private $make; /** * @ORM\Id * @ORM\Column(type="string") */ private $model; /** * * @ORM\OneToOne(targetEntity="Review", mappedBy="car", cascade={"persist"}) */ private $review; } class Review { /** * @ORM\Id * @ORM\OneToOne

Hibernate Many to Many on many to

泪湿孤枕 提交于 2019-12-08 07:41:11
问题 I´m trying to map an existing database to Hibernate using annotations. The problem is as follows. 'organization' and 'organization_roles' has a many to many relationship which is resolved in a table 'organization_has_roles' using the two primary keys as a composite primary key in the join table. Next there is a 'users' table. Users can have a single role in multiple organizations. This is again resolved in a join table named 'users_has_organizations_and_role' which has a composite primary key

Ruby On Rails multiple composite primary keys question

久未见 提交于 2019-12-08 04:42:59
问题 I am a new guy in Ruby, and I have tables with these primary keys: transaction_types: transaction_type transaction_headers: transaction_type transaction_year transaction_id transaction_details: transaction_type transaction_year transaction_id city_id ticker_id tickers: city_id ticker_id Of course, those models have other non primary keys such as customer_id, connection_id or date, or user_id, etc, but those are not important for relationships, as those are merely data or I don't have any