(Gid char (6) primary key,
Tnumberh varchar (4) not null,
Tnumbera varchar (4) not null,
Rids char (18) not null,
Gcode char (1) not null,
Gdate date,
Foreign key (Tnumberh) references Team (Tnumber),
Foreign key (Tnumbera) references Team (Tnumber),
Foreign key references (Rid) referee (Rid)
);
Suppose to create the table, how to make Tnumberh and Tnumbera data can not be the same
CodePudding user response:
The triggerWhen insert the update to determine two field values are the same, the same tip can't insert, update
CodePudding user response:
You can also add constraint, can tryThe alter table game add constraint ck_ha check (Tnumberh & lt;> Tnumbera);
CodePudding user response:
- use the check constraint
SQL>
SQL> Create table test (int a, b, int);
The Table created
SQL> The alter table test add constraint chk_a_b check (a<> B);
Table altered
SQL> - a successful
SQL> Insert into test values (100200);
1 row inserted
SQL> - a failure
SQL> Insert into test values (100100);
Insert into test values (100100)
ORA - 02290: a violation of check constraint conditions (TEST_USER. CHK_A_B)
SQL> A10 col a format;
SQL> A10 col b format;
SQL> Select * from the test;
A, B
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
100, 200,
SQL> Drop table test purge;
Table dropped
SQL>
CodePudding user response:
1, the business system restricts the2, the trigger limit
3, the field of the check constraint limit
The alter table Game
Add the constraint CK1
Check (Tnumberh!=Tnumbera);
CodePudding user response: