We have two tables with a one-to-many relationship. We would like to apply a restriction to at least one child record for this parent record.
Is it possible?
If not, will you replace the circuit with a more complex one to support this limitation? If so, how would you do it?
Edit: I am using SQL Server 2005
, " ". , , , , .
.
, back-end , PostgreSQL.
?
Create Table ParentTable ( ParentID ChildID not null, Primary Key (ParentID), Foreign Key (ChildID ) references Childtable (ChildID)); )
- , , before insert trigger .
before insert trigger
CREATE or REPLACE TRIGGER trigger_name BEFORE INSERT ON ParentTable FOR EACH ROW BEGIN -- ( insert new row into ChildTable ) -- update childID column in ParentTable END;
- " ", . , , .
, . . , , , .
- SQL Server.
1) - , . . , , - , .
2) CTE , CTE , ( ). , , .
3) , , . . , , , .
, , , , , .
, . , null ( ). ( ), , .
, SQL Server , .
- , !
P.S. , , , , , , .
P.P.S , null , , , , . , , . , , . , , , , .
, Oracle rel.11.2.4.
, PK, COUNT PK. - , NO_DATA_FOUND 0.
CHILD_COUNT .
CHILD_COUNT
CHECK CHILD_COUNT CHILD_COUNT > 0
CHILD_COUNT > 0
:
COMMIT
NOTE. I do not need a virtual column if Oracle allowed to use CHECK constraintsbased on user-defined functions in rel.11.2.4.
CHECK constraints
Source: https://habr.com/ru/post/1706465/More articles:both the top and bottom axes in pylab (for example, w / different units) (or left and right) - matplotlibRewriting url / regex debugging - url-rewritingDevExpress Microsoft Visual C # - c #__doPostback - call code for events from JavaScript? - javascriptDynamically display links using ASP.NET LoginView - asp.netSplitting a DLL utility into smaller components in C ++ - c ++Should a web browser delete all `session 'cookies (expiry = 0) upon exit? - browserStoring jquery code in external file and directory structure? - javascriptHow to count the number of lines in a large CSV file using Perl? - perlWebPart Security - sharepointAll Articles