我试图在外键更改中执行操作(删除/更新时)。
我试图在INFORMATION_SCHEMA.key_column_usage中查看它:
SELECT *
FROM `INFORMATION_SCHEMA`.`key_column_usage`
WHERE `referenced_table_schema` = '{$this->dbName}'
AND `referenced_table_name` IS NOT NULL
AND `table_name` = '{$this->tableName}'
它显示如下:
0 =>
array (size=12)
'CONSTRAINT_CATALOG' => string 'def' (length=3)
'CONSTRAINT_SCHEMA' => string 'test' (length=4)
'CONSTRAINT_NAME' => string 'profiles_ibfk_1' (length=15)
'TABLE_CATALOG' => string 'def' (length=3)
'TABLE_SCHEMA' => string 'test' (length=4)
'TABLE_NAME' => string 'profiles' (length=8)
'COLUMN_NAME' => string 'id' (length=2)
'ORDINAL_POSITION' => string '1' (length=1)
'POSITION_IN_UNIQUE_CONSTRAINT' => string '1' (length=1)
'REFERENCED_TABLE_SCHEMA' => string 'test' (length=4)
'REFERENCED_TABLE_NAME' => string 'users' (length=5)
'REFERENCED_COLUMN_NAME' => string 'id' (length=2)
....
我也尝试了INFORMATION_SCHEMA.TABLE_CONSTRAITS而且我得到了:
0 =>
array (size=6)
'CONSTRAINT_CATALOG' => string 'def' (length=3)
'CONSTRAINT_SCHEMA' => string 'test' (length=4)
'CONSTRAINT_NAME' => string 'PRIMARY' (length=7)
'TABLE_SCHEMA' => string 'test' (length=4)
'TABLE_NAME' => string 'profiles' (length=8)
'CONSTRAINT_TYPE' => string 'PRIMARY KEY' (length=11)
....
在2个案例中没有关于删除/更新的操作。
我能得到它吗?怎么样?如果我当然可以。
答案 0 :(得分:2)
从REFERENTIAL_CONSTRAINTS
信息架构中选择UPDATE_RULE
和DELETE_RULE
:
SELECT CONSTRAINT_NAME, UPDATE_RULE, DELETE_RULE
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE UNIQUE_CONSTRAINT_SCHEMA = '{$this->dbName}'
AND REFERENCED_TABLE_NAME IS NOT NULL
AND TABLE_NAME = '{$this->tableName}'
记录在案:
UPDATE_RULE
或DELETE_RULE
的可能值为CASCADE
,SET NULL
,SET DEFAULT
,RESTRICT
,NO ACTION
。< / p>
答案 1 :(得分:0)