I know that it’s not a good method to use two tables with mutual foreign key definitions, but I don’t understand the difficulties that arise in the database. An example: I’ve a table city and a table state. City.city points at state.capitalcity and state.state points at city.state. I would appreciate any help, thanks. Answer That’s fine. The problem arises when
Tag: foreign-keys
SQL – Update multiple tables, the same column across one query
I have a postgres database There are 3 tables, I’m trying to make a sql UPDATE statement that updates an active column in each table. Table1 has a field record that looks like this: Table2 Table3 is the same as table 2 I need a query that looks for the name “Digital Only” and it’s ID on table1. Update it’s
foreign key column doesn’t want to take an insert says column can’t be null
i’m trying to populate a foreign key column ‘boss_id’ from a junction table called ‘clown_boss’ boss_id is new self-referencing foreign key that is meant to hold the ‘id’ value of the clown’s boss. i already have a populated junction table that contains ‘id’ from clown_info table and newly created ‘boss_id’ that also references ‘id’ from clown. this is what clown_info
SQL table join on itself but allow “0” value
Okay so i have a simple table “category” on this table categories and subcategories are saved. categories have “parent_id=0”, and subcategories have a “parent_id” that equals the row_id of the …
Can Foreign Key on a table be three different tables as primary keys (each table primary key data is different)?
I have a reminder table (ParentId) – Foreign key to ProductId from Product and also OrderId from Order table. Is it possible? When I try to insert the data for the Reminder table belongs to OrderId, I’m getting Foreign-Key constraint error. Answer You can do this with a bit of work, using foreign key relationships and computed columns. This does
How to design tables with foreign key but value is NULL in MYSQL?
I am trying to design a database with 2 tables. Project and Student. Student table records what project each student selects, and the student could only select a project that exists in the project table. However, when a student first enrolls in the class, I want to insert his info into the student table but at that time, he did
The INSERT statement conflicted with the FOREIGN KEY constraint “FK__…”
I’m a very new beginner with SQL and I’m battling a problem I can’t seem to find the answer to. I’ve found similar questions here on Stack Overflow but I still can’t see what I’m supposed to change in my code to make it work. I’ve got 4 tables in a relation as follows: Then, I’ve got three procedures that
Delete records referenced by other records in different tables
I have a following requirement: I need to delete records from one table based on the given ID, now this table is referenced by another table and that other table is referenced by yet another table and that last table is also referenced by another table, so I have a chain like this: table_1 <- table_2 <- table_3 <- table_4
Ruby Foreign Key Constraints in Database vs Model
I have the following models in a Rails app. This setup has worked fine since normally when I would like to add a new VendorPromo to a vendor, there’s a dropdown in the view of available Promos to choose from. Now, I’m enabling the creation of new VendorPromos via an API. However, this current set up will allow the creation
Can I use two values of a foreign key in on table?
I have a ‘users’ table, and there is also a table ‘alerts’. And in the ‘alert’ table, I want to use ‘users.id’ two times representing two different users of a ‘users’ table as a foreign keys in ‘alert’…