當前位置:首頁 » 操作系統 » 資料庫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

熱點內容
水電煤演算法 發布:2025-07-04 18:36:44 瀏覽:328
天翼視訊緩存文件夾 發布:2025-07-04 18:36:43 瀏覽:96
unix網路編程第2卷 發布:2025-07-04 18:33:41 瀏覽:780
編譯歷史 發布:2025-07-04 18:23:01 瀏覽:851
空調壓縮機種類 發布:2025-07-04 18:13:58 瀏覽:242
中國有ip6伺服器嗎 發布:2025-07-04 17:58:56 瀏覽:726
第六章編譯原理答案 發布:2025-07-04 17:37:55 瀏覽:40
php內存優化 發布:2025-07-04 17:25:54 瀏覽:664
威綸觸摸屏如何設置時間限制密碼 發布:2025-07-04 17:25:50 瀏覽:418
python列表的遍歷 發布:2025-07-04 17:24:20 瀏覽:24