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--
This article mainly introduces how to establish constraints in mysql, which can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Mysql establishes the constraint method: 1, when creating the table, the code is [constraint index name foreign key (foreign key column)]; 2, after the table is created, the primary key constraint [alter table table_name add primary key (field)].
Mysql's method of establishing constraints:
The first one: when creating a table
Create table table_name (column name 1 data type (int) primary key auto_increment, column name 2 data type not null, column name 3 data type unique, column name 4 data type default 'value', constraint index name foreign key (foreign key column) references primary key table (primary key column) on delete cascade | on delete set null)
The second kind: after the completion of the table
1. Primary key constraint add: alter table table_name add primary key (field) delete: alter table table_name drop primary key2. Non-empty constraint add: alter table table_name modify column name data type not null delete: alter table table_name modify column name data type null3. Unique constraint add: alter table table_name add unique constraint name (field) delete: alter table table_name drop key constraint name 4. Automatic growth add: alter table table_name modify column name int auto_increment delete: alter table table_name modify column name int 5. Foreign key constraint add: alter table table_name add constraint constraint name foreign key (foreign key column) references primary key table (primary key column) delete: first step: delete foreign key alter table table_name drop foreign key constraint name second step: delete index alter table table_name drop index index name [^ 1]: constraint name and index name are the same 6. Default value add: alter table table_name alter listing set default 'value' deletion: alter table table_name alter listing drop default thank you for carefully reading this article, I hope the editor to share how to establish constraints on mysql content to help everyone, but also hope that you support a lot, pay attention to the industry information channel, find problems, detailed solutions waiting for you to learn!
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.