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--
Next, let's learn about the two ways of constraining Mysql to create foreign keys. I believe you will benefit a lot after reading it. The text is not much in essence. I hope you can restrict Mysql to create foreign keys in two ways. This short article is what you want.
By adding foreign key constraints to the table field of mysql, the consistency and integrity of the data can be effectively maintained, and the data will not be prone to problems.
1. Create a foreign key constraint directly when creating a table
Create table books (bookid number (10) not null primary key, bookName varchar2 (20) not null, price number (10dint 2), categoryId number (10) not null references Category (id)-Foreign key constraint)
Note: you must create a reference table before you can create a foreign key constraint, that is, you must have an existing table Category, followed by book
2. Create the table first. After the table is created successfully, add the foreign key constraint separately.
Create table books (bookid number (10) not null primary key, bookName varchar2 (20) not null, price number (10dag2), categoryId number (10) not null); ALTER TABLE books ADD CONSTRAINT FK_Book_categoryid FOREIGN KEY (categoryId) REFERENCES Category (id)
The above two ways are currently the way to add foreign key constraints in Mysql. I hope that when you use the associated table in the future, you can add foreign key constraints to some fields of the table, so that the data can maintain integrity.
After reading this article on the two ways of constraining Mysql to create foreign keys, many readers will want to know more about it. For more industry information, you can follow our industry information section.
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.