In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How does mysql query a foreign key constraint? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
Mysql query the foreign key constraints of a table: use the "SHOW CREATE TABLE" statement in the syntax format "SHOW CREATE TABLE;" to display all constraints on the use of the data table name, including primary key constraints, foreign key constraints, non-null constraints, unique constraints, and so on.
In MySQL, you can use the SHOW CREATE TABLE statement to view the constraints in the table and then query the foreign key constraints.
The format of the constraint syntax in the view data table is as follows:
SHOW CREATE TABLE
Example
Create the data table tb_emp8 and specify id as the primary key constraint, name as the only constraint, deptId as the non-empty constraint and foreign key constraint, and then look at the constraints in the table. The result of running the SQL statement is as follows.
Mysql > CREATE TABLE tb_emp8-> (- > id INT (11) PRIMARY KEY,-> name VARCHAR (22) UNIQUE,-> deptId INT (11) NOT NULL,-> salary FLOAT DEFAULT 0,-> CHECK (salary > 0),-> FOREIGN KEY (deptId) REFERENCES tb_dept1 (id)->) Query OK, 0 rows affected (0.37 sec) mysql > SHOW CREATE TABLE tb_emp8\ Graph * 1. Row * * Table: tb_emp8Create Table: CREATE TABLE `tb_ emp8` (`id`int (11) NOT NULL, `name` varchar (22) DEFAULT NULL, `deptId` int (11) NOT NULL, `salary`float DEFAULT'0' PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `deptId` (`deptId`), CONSTRAINT `deptId` FOREIGN KEY (`deptId`) REFERENCES `tb_ dept1` (`id`) ENGINE=InnoDB DEFAULT CHARSET=gb23121 row in set (0.19 sec) Thank you for reading! After reading the above, do you have a general understanding of mysql's method of querying an off-table key constraint? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.