No, you do not. The term link refers to pointer chains in the old network databases. Did you mean a REFERENCE, which is totally different? Links are for traversals and have no DRI actions. If you had followed basic forum netiquette, we would see the DDL you ha ve tried. Please fix this and we can go at it again.
No, rows are not records. SQL only has referencing, not associations. Your narrative is all pure Network Database terminology!
I know that this is probably your first year of SQL and RDBMS, but if you takr the timr to learn the proper terms, you will learn the proper concepts and this will save your butt later.
You have now hit on a weak spot in SQL! We use a set-oriented model of data. This means an empty set is just fine with us.We have trouble at the conceptual level with “:at least reference in the PCTC table to the PCT table”.
Back in the network model you have in your mindset, a pointer had to point at something, so you guys had problems with emptiness.
Here is my guess for a very bad skeleton. You would never use numeric types for identifiers, etc. but all we have is your sample data.
CREATE TABLE PCT
(tran_num INTEGER NOT NULL PRIMARY KEY,
patient_id INTEGER NOT NULL);
CREATE TABLE PCTC
(cov_num INTEGER NOT NULL PRIMARY KEY,
tran_num INTEGER NOT NULL
REFERENCES PCT (tran_num)
ON DELETE CASCADE,
payor_name VARCHAR(10) NOT NULL);
CREATE VIEW PCTC_X
SELECT cov_num, tran_num, payor_name
WHERE PTC.tran_num = PCTC.tran_num)
WITH CHECK OPTION;
This is tricky and lots of experienced programmers do not know it. The WITH CHECK OPTION will force the SQL engine to evaluate the WHERE clause on every update, insert and delete. This is portable ANSI/ISO Standard SQL. No, triggers cannot be optimized or ported among SQL products. And they are procedural code
Such views have to be updatable. All your work has to be done thru this view (use the GRANT/DENY stuff in the DCL to protect the base table). You can add a row to PTC, but it will not show up in PCTC_X until you add one or more matching rows in PCTC.
Write a procedure to handle insertions into two tables in one transaction. There are some tricks here, but that is another topic. See why I say it take 3-5 years to become a good SQL programmer?