foreign-keys

Query to find foreign keys

≯℡__Kan透↙ 提交于 2019-12-19 00:22:29
问题 I have a database where I need to drop some foreign keys, but I don't know beforehand whether the foreign keys still exist. I've found some stored procedures (http://forums.mysql.com/read.php?97,218825,247526) that does the trick, but I don't want to create a stored procedure for this. I've tried to use the query inside the stored procedure, but I get an error using "IF EXISTS (SELECT NULL FROM etc.. etc... Can I only use IF EXISTS in stored procedures? right now, the only thing I can run is

JPA not generating “on delete set null” FK restrictions

筅森魡賤 提交于 2019-12-18 21:03:27
问题 I have two related clases JPA-annotated. Alarm and Status. One Alarm can have one Status. What I need is to be able to delete one Status and "propagate" a null value to the Alarms that are in that Status that has been deleted. That is, I need the foreign key to be defined as " on delete set null ". @Entity public class Alarm { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence") @SequenceGenerator(name="sequence", sequenceName="alarm_pk_seq") private Integer id;

JPA not generating “on delete set null” FK restrictions

拥有回忆 提交于 2019-12-18 21:03:01
问题 I have two related clases JPA-annotated. Alarm and Status. One Alarm can have one Status. What I need is to be able to delete one Status and "propagate" a null value to the Alarms that are in that Status that has been deleted. That is, I need the foreign key to be defined as " on delete set null ". @Entity public class Alarm { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence") @SequenceGenerator(name="sequence", sequenceName="alarm_pk_seq") private Integer id;

Can foreign key references contain NULL values in PostgreSQL?

元气小坏坏 提交于 2019-12-18 20:32:47
问题 As an example create table indexing_table ( id SERIAL PRIMARY KEY, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), ); Is there a difference between the following tables? Table 1: create table referencing_table ( indexing_table_id INTEGER references indexing_table ); Table 2: create table referencing_table ( indexing_table_id INTEGER references indexing_table NOT NULL ); Alternatively, in the case of Table 1, where there is no NOT NULL constraint, are we allowed to insert records containing

How can I get the foreign keys of a table in mysql

﹥>﹥吖頭↗ 提交于 2019-12-18 17:18:38
问题 I am creating a class which, takes a table from a database, and displays it to a web-page, with as much functionality as possible. One of the things I would like to support, would be having the class detect which columns in the table have a foreign key constraint on them, so that it can then go to those tables, get all of their values and use them in a select-box which is called when you edit those fields, to avoid someone violating foreign key constraints, The main problem is discovering

create foreign key without a primary key

一笑奈何 提交于 2019-12-18 15:12:17
问题 Why is it necessary to have a primary key on a column of one table to which a column of the other table having foreign key references. create table D(Did int) create table E(Eid int foreign key references D(Did)) The above query gives error: There are no primary or candidate keys in the referenced table 'D' that match the referencing column list in the foreign key 'FK__E__Eid__79C80F94'. 回答1: Easy. If you have 2 values the same in the parent table, how do you know which one to associate child

create foreign key without a primary key

为君一笑 提交于 2019-12-18 15:11:28
问题 Why is it necessary to have a primary key on a column of one table to which a column of the other table having foreign key references. create table D(Did int) create table E(Eid int foreign key references D(Did)) The above query gives error: There are no primary or candidate keys in the referenced table 'D' that match the referencing column list in the foreign key 'FK__E__Eid__79C80F94'. 回答1: Easy. If you have 2 values the same in the parent table, how do you know which one to associate child

Foreign keys in alternate schemas with Oracle?

时光毁灭记忆、已成空白 提交于 2019-12-18 14:56:44
问题 I have two schemas, let's call them BOB and FRED. I need to call a table in schema FRED from schema BOB to use the primary key in that table as a foreign key. I've set up the appropriate grants for schema FRED to allow BOB access to it, but whenever I run the script, it complains that I do not have the correct permissions. Is there another setting that I need to change somewhere? Can this even be done? My FK creation is as follows: ALTER TABLE "BOB"."ITEMGROUP" WITH CHECK ADD CONSTRAINT FK

ORMlite Android foreign key support

我的梦境 提交于 2019-12-18 12:53:10
问题 I am not clever from ORMlite documentation. Is is possible to declare in class, that this parameter is foreign key? e.g. I have table Customer: @DatabaseTable(tableName = "customer") public class Customer { @DatabaseField(id = true) private String customerName; @DatabaseField private String customerSurname; @DatabaseField(foreign = true) private String accountNameHolder; @DatabaseField private int age; public Customer() { } } AccountNameHolder should aim towards DatabaseField name from table

adding a foreign key with Code First migration

╄→гoц情女王★ 提交于 2019-12-18 11:07:01
问题 I have an error when trying to update my database after adding a migration. Here are my classes before add-migration public class Product { public Product() { } public int ProductId { get; set; } public string Name { get; set; } public decimal Price { get; set; } public bool Istaxable { get; set; } public string DefaultImage { get; set; } public IList<Feature> Features { get; set; } public IList<Descriptor> Descriptors { get; set; } public IList<Image> Images { get; set; } public IList