我真的不懂SQL语言,我的一个表中有一个条件,我无法理解如何解决这个问题。如果有人可以帮助我,那就太好了。问题是我想要ON DELETE CASCADE
的IF条件。
“如果患者被移除 从系统,然后患者的约会也 从系统中删除;并且,医生只能被移除 如果医生没有预约,可以从系统中找到。“
我目前正在使用ON DELETE CASCADE
用于患者FOREIGN KEY,但我不确定我将用于医生的情况,因为它需要在进行ON DELETE CASCADE
之前检查。
答案 0 :(得分:1)
不要为医生提供外键的任何import os
import re
scan_dir = r"xxxx"
out_dir = r"xxxx"
process_tables = {"MM_WMS_WORK_LOCATION": "DESIGNER_MM_WMS_WORK_LOCATION",
"MM_WMS_DESIGN": "DESIGNER_MM_WMS_DESIGN",
"MM_WMS_WORK_REQUEST": "DESIGNER_MM_WMS_WORK_REQUEST",
"MM_WMS_COMPATIBLE_UNIT": "DESIGNER_MM_WMS_COMP_UNIT",
"MM_WMS_DN_COST_FACTOR": "DESIGNER_MM_WMS_DN_COST_FACTOR",
"MM_WMS_CU_COST_FACTOR": "DESIGNER_MM_WMS_CU_COST_FACTOR",
"MM_WMS_WR_USERS": "DESIGNER_MM_WMS_WR_USERS",
"MM_PX_CURRENT_STATE": "DESIGNER_MM_PX_CURRENT_STATE"}
sql_list = os.listdir(scan_dir)
for sql in sql_list:
if sql[-4:] == ".sql":
with open(os.path.join(scan_dir, sql), "r") as sql_in:
sql_out = sql_in.read()
for old_name, new_name in process_tables.items():
regex = re.compile(old_name + "\b", re.IGNORECASE)
sql_out = regex.sub(new_name.lower(), sql_out)
with open(os.path.join(out_dir, sql[:-4] + " Designer Test.sql"), "w") as file_out:
file_out.write(sql_out)
条款。任何尝试删除仍然被约会引用的医生都将失败,因为它会违反外键。只是,如果在他们的任命中没有更多的参考,可以删除医生。