Are 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