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)05/31 Report--
Mysql about the table operation is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Create a database
Createdatabase database name
Switch database
Use database name
Build a table:
Createtable table name (
Field name 1, type, constraint
Field name 2, type, constraint
...
)
Constraints:
1. Primary key constraint
1) add primarykey to the field type directly when creating the table
2) add the constraint constraint name primarykey (field name) at the end of the table
3) modify altertable table name addconstraint constraint name primarykey (field name) outside the table
two。 Check constraint
1) add check (constraint) directly after the table type is created
2) add the constraint constraint name check (constraint condition) at the end of the table
3) modify the altertable table name outside the table addconstraint constraint name check (constraint condition)
Note: mysql does not support checking constraints, but writing check constraints will not report an error
3. Non-empty constraint
1) add notnull directly after creating the type of the table
2) add the constraint constraint name check (field name isnotnull) at the end of the table
3) modify the altertable table name modify field name field type notnull outside the table
4. Unique constraint
1) add unique directly after creating the type of the table
2) add the constraint constraint name unqiue (field name) at the end of the table
3) modify the altertable table name addconstraint constraint name unique (field name) outside the table
5. Foreign key constraint
1) add the references parent table name (parent table primary key name) directly after creating the table type
2) add the constraint constraint name foreignkey (field name) references parent table name (parent table primary key name) at the end of the table
3) modify altertable table name addconstraint constraint name foreignkey (field name) references parent table name (parent table primary key name) ondeletesetnullonupdatacascade outside the table
6. Default constraint
1) add the default default value directly after creating the type of the table
2) modify the altertable table name addconstraint constraint name outside the table
Delete constraint
Altertable table name dropconstraint constraint name
Modification of table
1) add a field
Altertable table name add field name field type Note: when there is already a value in the table, you cannot add a non-null constraint
2) Delete a field
Altertable table name drop field name
3) modify the field type
Altertable table name modify field name new field type
4) modify the field name
Altertable table name change field name new field name field type
5) modify the table name
Altertable table name renameas new table name
6) delete the table
Droptable table name
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.