當前位置:首頁 » 操作系統 » 資料庫onupdate

資料庫onupdate

發布時間: 2022-09-21 19:04:36

① on update cascade 和on delete cascade 作用區別

這是資料庫外鍵定義的一個可選項,用來設置當主鍵表中的被參考列的數據發生變化時,外鍵表中響應欄位的變換規則的。update 則是主鍵表中被參考欄位的值更新,delete是指在主鍵表中刪除一條記錄:
on update 和 on delete 後面可以跟的詞語有四個
no action , set null , set default ,cascade
no action 表示 不做任何操作,
set null 表示在外鍵表中將相應欄位設置為null
set default 表示設置為默認值
cascade 表示級聯操作,就是說,如果主鍵表中被參考欄位更新,外鍵表中也更新,主鍵表中的記錄被刪除,外鍵表中改行也相應刪除

② 資料庫刪除列時,總提示:關鍵字 「cascade」 附近有語法錯誤,這是怎麼回事

級聯更新或者級聯刪除是定義在表裡面的,而不是在執行某個sql操作的時候定義的!
例如:有個a表中的studentID外鍵引用了你現在的student表的uid欄位,那麼在表a上就可以用
alter table a
add constraint FK_OA_REDB foreign key (studentID)
references student(uid)
on update cascade on delete cascade
go
然後你在 student刪除一條記錄的時候 a表中對應uid的記錄就會同時被刪除了

③ 資料庫中什麼是「級聯更新關聯欄位」和「級聯刪除關聯欄位」

sql的外鍵約束可以實現級聯刪除與級聯更新;
oracle則只充許級聯刪除。
sql級聯刪除與級聯更新使用格式:
create
table
a001(id
int
primary
key,name
varchar(20))
create
table
a002(id
int
references
a001(id)on
delete
cascade
on
update
cascade,age
tinyint)
oracle級聯刪除使用格式:
create
table
a001(id
int
primay
key,name
varchar2(20))
create
table
a002(id
int
references
a001(id)on
delete
cascade,age
number(2,0))

④ 資料庫加外鍵一定要寫on delete no action on update cascade嗎

不一定,具體要看你要增加什麼樣的約束,也可以 on delete cascade或on update no action

⑤ 如何修改資料庫中主外鍵約束的數據

你在建立外鍵的時候要指定更新的關聯,這樣刪除User中的一筆記錄,所有以User表的UserId為外鍵的表的記錄都會刪除,修改User中UserId的值,所有所有以User表的UserId為外鍵的表的記錄都會更新這個UserId的值

比如MSSQL中:
alter table tbl_xxx
add constraint FK_xxx foreign key (lodNo)
references tbl_aaa (loNo)
on update cascade on delete cascade
注意on update cascade on delete cascade

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:552
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:836
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:541
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:719
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:643
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:959
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:215
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:71
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:763
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:668