Activate foreign keys in SQL Server
When the FOREIGN KEY foreign key in SQL Server has been disabled, you can enable / re-enable with the ALTER TABLE command.
The syntax for activating foreign keys in SQL Server
ALTER TABLE ten_bang
CHECK CONSTRAINT fk_ten;
Variable name or variable value
ten_bang
The name of the table to which the foreign key has been created.
fk_ten
The name of the foreign key you want to disable.
For example
CREATE TABLE sanpham
( id_sanpham INT PRIMARY KEY,
ten_sanpham VARCHAR(50) NOT NULL,
phan_loai VARCHAR(25)
);
CREATE TABLE hangtonkho
( id_hangtonkho INT PRIMARY KEY,
id_sanpham INT NOT NULL,
soluong INT,
luong_toithieu INT,
luong_toida INT,
CONSTRAINT fk_htk_id_sanpham
FOREIGN KEY (id_sanpham)
REFERENCES sanpham (id_sanpham)
);
In this example, we created the parent table, sanpham, with the primary key including the information field id_sanpham. Then there is a child table named hangtonkho with a foreign key with deletion constraint. The CREATE TABLE statement creates a foreign key on the hangtonkho table named fk_htk_id_sanpham. The foreign key forms the relationship between the id_sanpham column in the hangtonkho table and id_sanpham in the sanpham table.
- Foreign Key (Cascade Delete) in SQL Server
- Foreign Key (Set Null) foreign key in SQL Server
If you want to re-enable the foreign key, run the following command.
ALTER TABLE hangtonkho
CHECK CONSTRAINT fk
_htk_id_sanpham;
The example above uses the ALTER TABLE command to re-enable the foreign key named fk_htk_id_sanpham in the hangtonkho table.
Previous article: Disable foreign key in SQL Server
The following article: Unique binding in SQL Server
You should read it
- Foreign Key with Cascade Delete in SQL Server
- Foreign Key with Set Null in SQL Server
- Disable foreign key in SQL Server
- Need to be wary of foreign objects in the ear
- The 10 best 'jobs' are available only to those who know a foreign language
- 7 compelling reasons for you to definitely learn a foreign language
- 7 simple tips to help you learn new languages in just one week
- Good news: Learning a foreign language helps increase brain elasticity
May be interested
- Create activity in Gitin this chapter, we will learn how to create a remote git repository, from which we will mention it as a git server. we need a git server to allow the team to collaborate.
- List of Win 10 Pro Keys with the latest permanent copyright activationto activate the windows 10 license, users need to spend a large amount of money to buy the win 10 pro key and activate it. in that case, readers can save money and use the win 10 pro key codes compiled by taimienphi in this article.
- How does the Windows Product Activation (WPA) work?windows product activation, or wpa, is a licensing process introduced by microsoft corporation on all versions of windows operating systems. wpa was first introduced on windows xp and still exists on windows server 2003, windows vista, windows server 2008 and windows 7.
- How to log in to SSH server with GPG keymaintaining ssh credentials is an important part of every administrator's security protocol. today's article will show you how you can reduce the keys you need to maintain by linking your ssh login information with your gpg key.
- Why do the F and J keys on the computer keyboard have horizontal lines?many people believe that floating edges are born to help visually impaired people interact with computers better, but this is not its original purpose.
- Need to be wary of foreign objects in the earforeign objects or insects flying into the ear can cause more harm than you think
- How to remap the Fn keys on macOSmany keys, like f3, may not be of much use and will be more useful when reusing it to perform other functions. today's article will show you how to remap the fn keys on macos.
- How to activate Ctrl + C / Ctrl + V to execute paste command in Command Prompt window?windows 10 finally supported with ctrl + c and ctrl + v keys to paste in the command prompt window. however, by default this feature is not enabled and you have to take a few simple steps to activate it.
- How to Fix Laptop Keystoday's tipsmake will show you how to fix unresponsive laptop keys. if after cleaning the base frame and reinstalling the keys the problem is still not resolved, you may need to completely replace the specific key or the entire keyboard.
- The 10 best 'jobs' are available only to those who know a foreign languagegame translators, coordinators at a non-profit international organization or flight attendants are considered extremely hot jobs for those who know foreign languages.