外键是用来校验表输入的数据值是否在值检查表(check table)中。外键检查只在前台输入值的时候起作用,如果通过SQL语句直接更改表中数据时,外键检查是无效的。这就表明外键并不一定能保证数据的完整性。
下面是创建外键的详细步骤:
1, SE11编辑需要创建外键的表,选中字段,点击外键按钮,
2, 在弹出的窗口界面中,输入值检查表,并点击‘Generate proposal’ 按钮,
3, 系统会根据Domain自动生成外键连接,如果自动生产的建议不需要修改,点击copy按钮,
Cardinality含义:
Cardinality specifies how many rows are allowed in foreign key table for a corresponding value in check table. It specifies as X: Y (where X point to check table and Y points to foreign key table).
The allowed values for X are
- X=1: if a row in check table deleted then the corresponding rows from foreign key table also deleted.
- X=C: Deletion of check table rows won’t affect the foreign key table rows.
The allowed values for Y are
- Y=1: For each row in check table only one row is allowed in foreign key table
- Y=C: For each row in check table maximum one row is allowed in foreign key table
- Y=N: For each row in check table there is always at least one row in foreign key table.
- Y=CN: There might or might not be rows in the foreign key table for each row in the check table.
这样外键就创建完毕,激活并保存表。
4, 测试外键
向表中插入值时,Dep ID 001不在值检查表中,
保存时,会报错,显示在状态栏中,新纪录不能插入,如下:
以上。
发表评论