The method of adding fields to mysql
This article mainly introduces the method of adding fields to mysql, which has a certain reference value and 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.
When writing sql statements in MySQL, it is very important to add fields, for example, when the created table is not enough to meet the requirements, you need to add fields, which has met the requirements.
First, take the table created below as an example:
CREATE TABLE IF NOT EXISTS `user` (`id` INT UNSIGNED AUTO_INCREMENT, `phone` CHAR (11) NOT NULL DEFAULT'', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
In the past, only the mobile phone number was saved, but now the information is more complete, and the name and creation time are required.
At this point, you need to use the method of adding fields.
ALTER TABLE `user`ADD `username` varchar (20) NULL DEFAULT''COMMENT' username 'AFTER `phone`, ADD `create_ at`username` creation time' AFTER `username`
AFTER means to add after a field. If not, add it to the end.
When creating tables and referring to other people's tables, it takes time to set up templates, such as using Navicat Premium tools to view other people's table information.
Thank you for reading this article carefully. I hope it will be helpful for everyone to share the method of adding fields in mysql. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!