foreign-keys

Hibernate foreign key as part of primary key

老子叫甜甜 提交于 2019-11-29 02:06:16
I have to work with hibernate and not very sure how solve this problem, I've 2 table with a 1..n relationship like this: ------- TABLE_A ------- first_id (pk) second_id (pk) [other fields] ------- TABLE_B ------- first_id (pk)(fk TABLE_A.first_id) second_id (pk)(fk TABLE_A.second_id) third_id (pk) [other fields] How can I manage this with Hibernate??? I don't have idea how to manage the primary key for the second table... There is an example which is completely similar to your case in the Hibernate reference documentation . Just before this example, you'll find the explanations. Here's the

natural key vs surrogate key an innodb foreign key

你离开我真会死。 提交于 2019-11-29 01:43:00
A question: I have 2 tables: Product id INT name VARCHAR(64) something TEXT else INT entirely BOOL and Ingredient id INT name VARCHAR(64) description TEXT Now I also have a link table Products_Ingredients product_id INT ingredient_id INT for my many to many relation. Now both products and ingredients will have unique names. So I can use names as natural keys... however will that be a good idea? Say I have a product: Paint Thinner Supreme with ingredient: Butylonitrotetrocycline Will that be a good idea to use those names as composite key in the link table? As much as I understand idea behind

Django admin inline: select_related

懵懂的女人 提交于 2019-11-29 01:35:40
问题 Using Django 1.8 on Python 3.4.1 with models: class Product(models.Model): name = models.CharField(max_length=255) # some more fields here def __str__(self): return self.name class PricedProduct(models.Model): product = models.ForeignKey(Product, related_name='prices') # some more fields here def __str__(self): return str(self.product) class Coming(models.Model): # some unimportant fields here class ComingProducts(models.Model): coming = models.ForeignKey(Coming) priced_product = models

MySQL cannot create foreign key constraint

我的未来我决定 提交于 2019-11-29 01:23:58
问题 I'm having some problems creating a foreign key to an existing table in a mysql database. I have the table exp : +-------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+-------+ | EID | varchar(45) | NO | PRI | NULL | | | Comment | text | YES | | NULL | | | Initials | varchar(255) | NO | | NULL | | | ExpDate | date | NO | | NULL | | | InsertDate | date | NO | | NULL | | |

SQL Server 2008: The columns in table do not match an existing primary key or unique constraint

你离开我真会死。 提交于 2019-11-29 01:22:31
问题 I need to make some changes to a SQL Server 2008 database. This requires the creation of a new table, and inserting a foreign key in the new table that references the Primary key of an already existing table. So I want to set up a relationship between my new tblTwo, which references the primary key of tblOne. However when I tried to do this (through SQL Server Management Studio) I got the following error: The columns in table 'tblOne' do not match an existing primary key or UNIQUE constraint

Delete all foreign keys in database(MySql)

℡╲_俬逩灬. 提交于 2019-11-29 01:20:15
I would like to rename a column in a table that is a foreign key to many tables. Apparently this is only possible if you delete the constraints, as I found out in this link . I dont want to delete all the constratints manually is there a way to delete all the foreign key constraints in the database? I have also tried SET FOREIGN_KEY_CHECKS=0; but I still cant rename the column. Executing the following query select * from information_schema.key_column_usage will show you all the constraints (with the column name, constraint type, table and schema) that exist in your database. You'll notice

Is it possible to drop all foreign key constraints on a table at once in mySQL 5?

心不动则不痛 提交于 2019-11-29 01:10:19
问题 In mySQL 5, is there a way to drop all foreign key constraints on a table with one SQL statement without referring to them by name? I'm writing a DB update script, and unfortunately some of the sites had constraints created with "wrong" names. I'm trying to avoid going in and getting the actual constraint names from the DB and inserting them back into SQL statements. 回答1: You can surely select * the table to a temp table, drop and recreate it, then copy back. 回答2: I have a solution similar to

What is difference between foreign key and reference key?

被刻印的时光 ゝ 提交于 2019-11-28 23:46:36
问题 I am very confused about those two terms. Are they the same or different? Some books and people say they are the same and others say they are different. I tried but couldn't find a conclusive answer. 回答1: I am supposing that you are talking about using the REFERENCES where the FOREIGN KEY keyword is not used, eg. author_id INTEGER REFERENCES author(id) ... instead of ... author_id INTEGER, FOREIGN KEY(author_id) REFERENCES author(id) The answer is, that it is simply shorthand syntax for the

SQL design around lack of cross-database foreign key references

落花浮王杯 提交于 2019-11-28 23:07:17
For better or worse, we have a solution that relies on multiple databases that all reference a common administration database. Databases ship as part of modules, and not all modules are required for an installation (probably why we have multiple databases in the first place). The admin database is required, however ... so it will always be there. I would like to bring some referential integrity and order to the chaos, but am stymied by SQL server's inability to do cross-database foreign keys. There is NOT a lot of churn in the database, but information will be inserted/updated by (ahem) non

unable to drop the foreign key

半腔热情 提交于 2019-11-28 22:50:34
I would like to drop the foreign key in my table but been into this error message mysql> alter table customers drop foreign key customerid; ERROR 1025 (HY000): Error on rename of '.\products\customers' to '.\products\#sql2-7ec-a3' (errno: 152) mysql> To avoid getting this error while trying to drop a foreign key, use the constraint name rather than the column name of the foreign key. When I tried mysql> ALTER TABLE mytable DROP PRIMARY KEY; I got error as ERROR 1025 (HY000): Error on rename of '.\database\#sql-454_3' to '.\database\mytable' (errno: 150). I solved it using: mysql> ALTER TABLE