SQL Server 17 - ON DELETE and ON UPDATE - ユーティージェーピー





"SQL Server 17 - ON DELETE and ON UPDATE" の動画はこちら


この動画をTwitterで共有!
外部プレーヤー埋め込みタグ


"SQL Server 17 - ON DELETE and ON UPDATE"のYouTube動画詳細情報


SQL Server 17 - ON DELETE and ON UPDATE


SQL Server 17 - ON DELETE and ON UPDATE

Now, what happens when you have successfully created a reference, and now you try deleting the parent? This is where the ON DELETE clause comes in. This is essentially how we configure how strict a foreign key is. There are 4 options you can give for an ON DELETE: Standard SQL Server NO ACTION Yes (Default) CASCADE Yes SET NULL Yes SET DEFAULT Yes Now the default is NO ACTION. This means that when you try to delete a parent row, SQL Server is going to throw an error and not let you. Cascade means that if you delete the parent row, any rows that reference that parent will also be deleted. This is pretty dangerous and not often recommended. SET NULL will set the foreign key to be NULL. Now obviously, this is going to require that the foreign key is not labelled NOT NULL. Finally, set DEFAULT will change the reference to the child row to some default value. We have not discussed defaults, but a column can have a default value. For example, we could make a deleted user in our Users table, and set the default for the foreign key to be the deleted user, and when any other users are deleted it will default to the deleted user UserId. In addition to the ON DELETE clause, there is the ON UPDATE clause. This one is a little less common because it configures what happens when a parent value changes. Obviously, when you are referencing a primary key, the ON UPDATE clause is nearly useless. That's because the primary key value is never supposed to change. If, on the other hand, we have a foreign key referencing a UNIQUE column that is not a primary key, it may change occasionally. So the only times you have to worry about the ON UPDATE clause is with foreign keys referencing UNIQUE columns that are not a primary key, and when you have natural keys that break the rules and actually do change at some point in time. The ON UPDATE clause has the same options as the ON DELETE clause and they all work the same way. Now, the last thing you need to know about foreign keys is that they must match the data type of the column you are referencing. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
動画ID:o-DFrboZYCo
投稿日時:2016年12月27日 03時00分
再生回数:4,618 回
コメント数:11
高く評価した人の数:113人
低く評価した人の数:6人


"SQL Server 17 - ON DELETE and ON UPDATE" の関連お勧め情報 検索結果




関連オススメ動画情報

スポンサードリンク

↑ PAGE TOP