foreign-keys

Inserting a foreign key into a table

痴心易碎 提交于 2019-12-11 11:36:06
问题 How to insert foreign key into a table? I have two table (Info and WorkDetails) where WorkDetails has a foreign key which refer to Info. Is this the correct way to implement? MyDatabaseHelper.java public void onCreate(SQLiteDatabase db) { db.execSQL("create table "+TABLE_INFO+"(ID INTEGER PRIMARY KEY ,Name TEXT,Weather TEXT, Date DATETIME, Status Text)"); db.execSQL("create table"+TABLE_WORKDETAILS+"(ID INTEGER PRIMARY KEY , Project TEXT, WorkDescription TEXT, Per Text, TimeIn DATETIME,

Is the ForeignKey annotation only used by HBM2DDL to generate the schema?

≯℡__Kan透↙ 提交于 2019-12-11 11:33:37
问题 I'm having an issue with how Hibernate generates foreign key names when using the TABLE_PER_CLASS inheritance strategy: Foreign keys have random number appended when using Hibernate's TABLE_PER_CLASS inheritance So I'm wondering if I can simply replace the annotation with the following: @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Entity abstract class Item { @ManyToOne @ForeignKey(name="FK_ITEM_ORG_CHANGEME") @JoinColumn(name="ORG_ID") private Organization org } That way I

reproduce such deadlock in mysql

随声附和 提交于 2019-12-11 11:23:50
问题 I got information from SHOW ENGINE INNODB STATUS *** (1) TRANSACTION: TRANSACTION 0 2799914, ACTIVE 1 sec, process no 4106, OS thread id 139808903796480 inserting mysql tables in use 1, locked 1 LOCK WAIT 10 lock struct(s), heap size 1216, 7 row lock(s), undo log entries 3 MySQL thread id 4284, query id 2889649 localhost 127.0.0.1 test update INSERT INTO shipping ..... *** (1) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 0 page no 436366 n bits 88 index `PRIMARY` of table

Hibernate. Foreign key mapping by id

断了今生、忘了曾经 提交于 2019-12-11 10:41:58
问题 I want to create @ManyToOne mapping between Acount and Record. One account can have a lot of records. But i don't want to add Account field in Record class or vice versa. Could you please help me to describe this in annotations? @Entity public class Account { @Id ... getId(); } @Entity public class Record { @Id ... getId(); @????? ... getAccountId(); } 回答1: Mapping entities to tables is the way Hibernate usually works, if you don't want the Account class in Record you can simply define

MySQL Multi-Delete. Is it possible to multi-delete referenced rows?

守給你的承諾、 提交于 2019-12-11 10:34:55
问题 If I have a parent table and a child table, is it possible to multi-delete the rows in them without having a "ON DELETE CASCADE" constraint? In this example: create table a(id int primary key); create table b(id int primary key, a_id int, constraint fkb foreign key (a_id) references a(id)); Is it not possible to do something like this in order to delete rows in tables a and b? :-( delete a, b from b inner join a on a.id = b.a_id where a.id = ?; Error Code: 1451. Cannot delete or update a

MySQL multiple foreign keys

谁说我不能喝 提交于 2019-12-11 10:32:59
问题 I'm new to setting up relational databases. I'm trying to create two tables in MySQL, a USER table and a COMPANY table. Both should be able to have multiple phone numbers associated with them, so I created a PHONE table and wanted to have a one-to-many relationship from both COMPANY to PHONE, and from USER to PHONE. There only seem to two options in what I am trying to do: Keep two foreign keys in PHONE, one referencing COMPANY, and one referencing USER. They would both default to NULL and

How to set cascade on SQLite database with compound primary foreign key?

荒凉一梦 提交于 2019-12-11 10:16:35
问题 I have a db that's structured with a supertype table as well as subtype tables like so: EVENT PatientId INTEGER, DateTime TEXT, EventTypeCode TEXT, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) different types of events have their own tables and have the same primary key, except that it's foreign. EXERCISE PatientId INTEGER, DateTime TEXT, EventTypeCode TEXT, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) ON CONFLICT IGNORE, CONSTRAINT "PrimaryKey" FOREIGN KEY ("PatientId",

can't create foreign key constraint

二次信任 提交于 2019-12-11 09:45:26
问题 CREATE TABLE share( `User_1` VARCHAR(50) NOT NULL, `User_2` VARCHAR(50) NOT NULL, PRIMARY KEY(`User_1`,`User_2`), CONSTRAINT `fk_1` FOREIGN KEY (`User_1`) REFERENCES user(`Dev_ID`) ON DELETE RESTRICT ON UPDATE CASCADE , CONSTRAINT `fk_2` FOREIGN KEY (`User_2`) REFERENCES user(`Dev_ID`) ON DELETE RESTRICT ON UPDATE CASCADE ); I get this error: {Foreign key constraint is incorrectly formed } I want to make a link between user1 and user2. 来源: https://stackoverflow.com/questions/10076921/cant

Specific Entity Framework Code First Many to 2 Model Mapping

狂风中的少年 提交于 2019-12-11 09:24:43
问题 I'm a bit of a loss here. Basically I have these two Models: public class Player { public int PlayerId { get; set; } public string Name { get; set; } public virtual ICollection<Game> Games { get; set; } } public class Game { public int GameId { get; set; } public virtual Player PlayerBlack { get; set; } public virtual Player PlayerWhite { get; set; } } Now the Database Schema, EF Code First creates for me, is not correct because the Game table gets 3 Foreign Keys (Playerblack, PlayerWhite and

Possible to Fix a Foreign Key in Yii without having set it up in the Database?

喜你入骨 提交于 2019-12-11 09:07:16
问题 I'm using phpMyAdmin for my database GUI and it's connecting to Yii Framework on my website. I wish for my products table for instance, to have a foreign key department_id which is a reference to the id field of my departments table. Unfortunately, I don't currently have the facility to set the foreign key up properly in phpMyAdmin, so department_id is just an indexed field. I cannot change the configuration of phpMyAdmin at the moment so it's stuck like it is without a foreign key and