Foreign Key Settings
I will start by mentioning that I am very new to databases. I am working in MySQL.Can anyone give me a layman's view of when you would use which settings for the foreign key options so when you would...
View ArticleDo any of the graph based/aware databases have good mechanisms for...
Do any of the graph-based/graph-aware databases (Neo4j, ArangoDB, OrientDB, or other) have mechanisms for maintaining referential integrity on a par with those offered by relational databases?I'm...
View ArticleHow to delete foreign key with lots of references
Table B have several thousand records that references table A with a foreign key.The application sends a request to delete the row from table A. It's important that the synchronous operation would be...
View ArticleConstraint - one boolean row is true, all other rows false
I have a column: standard BOOLEAN NOT NULLI would like to enforce one row True, and all others False. The are no FK's or anything else depending on this constraint. I know I can accomplish it with...
View ArticleNon-overlapping rectangles constrained to a boundary
I am trying to model placement of parts on a circuit board. Without anymeaningful constraints, my basic schema looks like this:create table part ( part_id bigserial primary key, name text not null,...
View ArticleConstraint to enforce "at least one" or "exactly one" in a database
Say we have users and each user can have multiple email addressesCREATE TABLE emails ( user_id integer, email_address text, is_active boolean)Some sample rowsuser_id | email_address | is_active1 |...
View ArticleHow can I define circular referential integrity constraints?
I have two tables mutually referencing each other, and I get this error when trying to insert into one of them: "Foreign key constraint is incorrectly formed".I have been stuck for three weeks this...
View ArticleON DELETE CASCADE not working
Trying to implement a simple user follower system in MySQL, using a junction table:CREATE TABLE users ( id int NOT NULL AUTO_INCREMENT, email varchar(255) NOT NULL, username varchar(25) NOT NULL,...
View ArticleOracle parent child move failed
I have two tables, a parent and child table, which have referential integrity declared between two tables and try to move both the tables so I can delete rows.I start with the child table and the move...
View ArticleForeign key to multiple tables via forwarding table
Problem statementI have a table with a column whose values are foriegn keys, but thetarget table of the foreign key differs from row to row. The relevanttable can be determined from the key value...
View ArticleAre there performance issues with FKs on different schemas?
In order to perform functional decomposition of a "big blob" of a database the first step we wanted to take is to separate different modules of the database into separate schemas on the same database...
View ArticleHow to implement a 'default' flag that can only be set on a single row
For example, with a table similar to this:create table foo(bar int identity, chk char(1) check (chk in('Y', 'N')));It doesn't matter if the flag is implemented as a char(1), a bit or whatever. I just...
View ArticleEnforcing constraints "two tables away"
I ran into some trouble modeling an electrical schematic in SQL.The structure I'd like to capture is part ←────────── pin↑↑part_inst ←───── pin_instwhere "inst" is short for "instance".For example, I...
View ArticleForeign Key - from same table and parent table
I have 2 tables.First table is parentCOLLECTIONS_OF_MAPSidtitle50013Geological Map Series50014Climate Map SeriesSecond table is a child (but whilst describing map layers, it also has entries that are...
View ArticleWhat is the correct way to map relationships between structurally similar...
I'm working on the usual comments table in postgres that has a one-to-many relationship with a commentable entity. In other words, one comment belongs to a post, and a post can have many comments.The...
View ArticleHow can I change the REFERENCE in a FOREIGN KEY?
After renaming some tables I get the following error:MariaDB [testdb]> INSERT INTO user_events (date, uid, operation, info) VALUES('2022-09-15','xyz','create',NULL);ERROR 1452 (23000): Cannot add or...
View ArticleFor each row create a linked row in another table with auto-generated ID
In Postgres, I have an existing table:thingsthing_idthing_namedestination_id10thing 10null15thing 15nullFor each row in that table, I want to add rows to two new related tables one of which has an...
View Article--- Article Not Found! ---
*** *** *** RSSing Note: Article is missing! We don't know where we put it!!. *** ***
View Article"Merge" two rows in a Postgres table, with foreign keys
I am keeping a database of books I've read, using the following two tables in PostgreSQL:CREATE TABLE authors ( id SERIAL PRIMARY KEY, name text);CREATE TABLE books ( id SERIAL PRIMARY KEY, title text,...
View ArticleDo I need a separate Id column for this "mapping" table?
I have a table of Producers and a table of Products, both of which are of the form:Id - int, Primary keyName - nvarcharA Producer can carry multiple Products, so I was going to create a table called...
View ArticleUse 2 columns of a table as foreign key in an other table to avoid...
I have two tables:ObjectContainer containerID INT NOT NULL PRIMARY KEY mainObjectID INT NOT NULL FOREIGN KEY REFERENCES Object (objectID)Object objectID INT NOT NULL PRIMARY KEY containerID INT NOT...
View Articlethe REFERENCES privilege is only about creating a foreign key constraint?...
Today I learned about GRANT REFERENCES. In years of SQL admin and dev work I never heard about it and never had issues with it.quote from MySQL 5.7 Reference Manual / GRANT SyntaxREFERENCES Enable...
View ArticleModeling strictly referential relationships to third-party databases
To be clear, I mean to ask this question from a strictly "Data Modelling and database-design, including referential-integrity" PoV.I am currently designing a database that will serve as an aggregation...
View ArticleER Diagram for Missed Visits
I have to design an ERD for a hypothetical scenario. In the scenario, the nurse at a rural clinic needs to get summary data regarding patient visits so she can reschedule canceled or no-show visits.For...
View ArticleVisualize the effects of a cascading delete or update?
In MySQL, I'm working with a database that has integrity constraints on foreign keys (nothing overly special here).Is there a method to somehow visualize the effects of a cascading delete or update?I...
View ArticleHow to enforce entity existence across N-tables - postgres
Let's say we decided to split user table in two, one will have data related to authentication, another basic user description: user_tableuser_id | name1 | Max2 | Alex3 | Should not be possible...
View ArticleModeling Polymorphic Relations in Postgres 15 with bi-directional (cyclic) FK...
I am drawn to this design like a moth to a flame. I've read rumblings that cyclic foreign keys are a nightmare. Generally, I can see why they should be avoided. In this particular case, however, I...
View ArticleMATCH FULL vs MATCH SIMPLE in foreign key constraints
I've noticed the clauses MATCH SIMPLE and MATCH FULL in phpPgAdmin, but I can't find a description in the docs.The default is MATCH SIMPLE. How do they function?
View ArticleCreate Constraint To Ensure Date Range Is Within Another Date Range
I am trying to create a scheduling application, and part of it requires the date range of a row to be within the date range of a row in another table, which it is referencing via a foreign key.Note:...
View ArticleWhat is an industry standard name for this self-referencing foreign key...
I'm currently in a battle with Entity Framework over trying to make a self-referencing relationship without having to add additional columns/properties. I have confirmed the foreign key I envision is...
View Article