foreign-keys

Possible to condense primary key/serial?

本小妞迷上赌 提交于 2019-12-01 23:19:57
I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out.. Well, Lets say I have Table1 and Table2. Table1 has 3 fields. RID, table2_rid,data So table1.table2_rid references table2.RID and this is expressed with a foreign key. In both the RID field is the primary key and is a serial type. What I would like to know is how to "condense" the primary keys? Like say you add 5 records and deleted record number 3. Your primary keys would look like 1 2 4 5 Well, how do I get to update everywhere so that the primary key(and

Does it ever make sense to have more than one foreign keys between two tables

只谈情不闲聊 提交于 2019-12-01 22:44:14
I was learning Sqlalchemy and noticed that a foreign key relation was defined by relating the table names without identifying the actual foreign key connecting the two tables, so I was thinking, if there are more than one foreign keys between the two tables(if it ever makes sense), sqlalchemy would fail to determine the key used to link the two tables. Anyway, my question is: does it ever make sense to have more than one foreign keys between two tables Yes, there are certainly cases where a table can have multiple foreign keys to different rows of a parent table. Here's an example: A table in

Deleting from a MySQL table with foreign key constraints

孤者浪人 提交于 2019-12-01 21:14:09
I have two tables, with some data loaded in it and the two reference each other. Table B references the primary key of Table A. I manually attempt to delete some table rows from Table A that are present in Table B, and I get this: #1451 - Cannot delete or update a parent row: a foreign key constraint fails ( TableA . TableB , CONSTRAINT TableB_ibfk_2 FOREIGN KEY ( column ) REFERENCES flashcard ( primaryKeyColumn )) I am not quite sure what's up here. From what I understand,if I delete some rows of TableA then they should automatically also delete the corresponding rows present in Table B (i.e

What is an easy way to list the foreign key contraints in an MDB?

故事扮演 提交于 2019-12-01 21:01:48
What is an easy way to list the foreign key contraints in an MDB? Is there a system table that can be queried in order to list this information? Specifically, I need to know whether any foreign key contraints exist in the MDB. Take a look at the results of select * from MSysRelationships . Or you can examine the relationships collection of the database object: Public Sub PrintRelationships() Dim varItem As Variant Dim varItem2 As Variant For Each varItem In CurrentDb.Relations Debug.Print varItem.Name Debug.Print " " & varItem.Table Debug.Print " " & varItem.ForeignTable For Each varItem2 In

JPA: Weird error when I try to persist an object

穿精又带淫゛_ 提交于 2019-12-01 20:13:32
I got a OneToMany relation between User and Group Group.java @Entity public class Group { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String groupid; @ManyToOne @JoinColumn(name="USER_FK") private User user; ... } User.java @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String userId; private String password; private String fname; private String lname; @OneToMany(mappedBy="user", cascade=CascadeType.ALL) private List<Group> groups; public void addGroup(Group group){ if(this.groups == null){ this.groups =

Should I make a foreign key that can be null or make a new table?

本秂侑毒 提交于 2019-12-01 19:30:48
I have a small question concerning with how I should design my database. I have a table dogs for an animal shelter and I have a table owners. In the table dogs all dogs that are and once were in the shelter are being put. Now I want to make a relation between the table dogs and the table owners. The problem is, in this example not all dogs have an owner, and since an owner can have more than one dog, a possible foreign key should be put in the table dogs (a dog can't have more than one owner, at least not in the administration of the shelter). But if I do that, some dogs (the ones in the

Hibernate how to use a constant as part of composite foreign reference

橙三吉。 提交于 2019-12-01 19:08:12
问题 I have a master table A with a composite primary key, consisting of two columns. One of these columns is a constant ("THE CONSTANT VALUE" in the code below). This table definition looks like the following: @Entity public class Master { @Id @Column(name = "SIGNIFICANT_KEY") private String realKey; @Id @Column(name = "CONSTANT_KEY") private String constantPartKey; } I have a detail table B, referencing master table A using only one (non-constant) column. I want to implement usual ManyToOne and

Hibernate how to use a constant as part of composite foreign reference

左心房为你撑大大i 提交于 2019-12-01 18:35:52
I have a master table A with a composite primary key, consisting of two columns. One of these columns is a constant ("THE CONSTANT VALUE" in the code below). This table definition looks like the following: @Entity public class Master { @Id @Column(name = "SIGNIFICANT_KEY") private String realKey; @Id @Column(name = "CONSTANT_KEY") private String constantPartKey; } I have a detail table B, referencing master table A using only one (non-constant) column. I want to implement usual ManyToOne and OneToMany relations between the two tables. Question : How can I handle this situation with Hibernate?

How to determine if a PropertyType is foreign key

血红的双手。 提交于 2019-12-01 18:14:44
I have the following class 'schakeling', generated with EF, representing a database table 'schakeling'. In the database 'id' is the primary key and 'plc_id' is a foreign key. public partial class schakeling { public schakeling() { this.verbruik = new HashSet<verbruik>(); } public int id { get; set; } public int plc_id { get; set; } public string var_output { get; set; } public string omschrijving { get; set; } public int vermogen { get; set; } public Nullable<bool> status { get; set; } public Nullable<byte> hourOn { get; set; } public Nullable<byte> minuteOn { get; set; } public Nullable<byte>

How to determine if a PropertyType is foreign key

蓝咒 提交于 2019-12-01 17:41:18
问题 I have the following class 'schakeling', generated with EF, representing a database table 'schakeling'. In the database 'id' is the primary key and 'plc_id' is a foreign key. public partial class schakeling { public schakeling() { this.verbruik = new HashSet<verbruik>(); } public int id { get; set; } public int plc_id { get; set; } public string var_output { get; set; } public string omschrijving { get; set; } public int vermogen { get; set; } public Nullable<bool> status { get; set; } public