当前位置:网站首页>MySQL | basic commands
MySQL | basic commands
2022-06-26 14:10:00 【wekidi】
1. Operating the database
- Create database
CREAT DATABASE [IF NOT EXISTS] name[] With or without - Delete database
DROP DATABASE [IF EXISTS] name - Using a database
use name - view the database
show DATABASE
2. Properties of fields
ZEROFILL: use 0 Filled with , The number of missing digits is 0 Fill in
Auto_InCrement: Self increasing , Default Auto +1, Usually used to design primary keys , You can set the starting value and the length of one increase by yourself :
- Current table setting step (AUTO_INCREMENT=100) : Only the current table
- SET @@auto_increment_increment=5 ; Affect all tables using auto increment ( overall situation )
NOT NULL: The column must have a value
DEFAULT: The default value is
Example
CREATE TABLE IF NOT EXISTS `user`(
`id` INT(4) NOT NULL AUTO_INCREMENT COMMENT ' Add notes , This is the user id',
`name` VARCHAR(30) NOT NULL COMMENT ' user name ',
`pwd` VARCHAR(30) NOT NULL COMMENT ' password '
PRIMARY KEY (`id`)
)ENGINE = INNODB
modify the database
Modify the name of the table :ALTER TABLE The old name of the table RENAME AS The new name of the table
Add fields ( attribute ): ALTER TABLE Table name ADD Field name attribute A field is a column of a table
Modify fields :
- ALTER TABLE Table name MODIFY Field name attribute
- ALTER TABLE Table name CHANGE Old field name new field name attribute ( Used to modify column names )
Delete field :ALTER TABLE Table name DROP Field name
Delete table :DROP TABLE [IF EXISTS] Table name
Add or delete check change
insert
INSERT INTO `user`(`pwd`) VALUES ('123');// Insert... For a single attribute
INSERT INTO `user`(`id`,`name`,`pwd`) VALUES ('3','FXL','564123'),('4','KKK','123456');// Insert multiple data
INSERT INTO `user` VALUES ('3','FXL','564123');// Omit field insertion , The premise is that all fields are satisfied . One-to-one correspondence
update
UPDATE `user` SET `id`='6' WHERE `name`= 'FXL';// Specified conditions
When not specified , All lines will be changed
delete
// Delete all
DELETE FROM `user`;
// Delete specified data
DELETE FROM `user` WHERE `id`=1;
DELETE and TRUNCATE The difference between :
DELETE You can conditionally delete (where Clause ), and TRUNCATE Only the entire table can be deleted
TRUNCATE Reset auto increment column , The counter will go to zero , and DELETE It won't affect self growth
DELETE Data manipulation language (DML - Data Manipulation Language), During operation, the original data will be put into rollback segment in , Can be rolled back ; and TRUNCATE It's data definition language (DDL - Data Definition Language), Operation will not be stored , Cannot roll back .
边栏推荐
- Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
- It is better and safer to choose which securities company to open an account for flush stock
- Guruiwat rushed to the Hong Kong stock exchange for listing: set "multiple firsts" and obtained an investment of 900million yuan from IDG capital
- PHP非对称加密算法(RSA)加密机制设计
- 7.consul service registration and discovery
- CloudCompare——泊松重建
- [jsoi2015] string tree
- Firewall introduction
- "Scoi2016" delicious problem solution
- Niuke challenge 53:c. strange magic array
猜你喜欢

永远不要使用Redis过期监听实现定时任务!

HW蓝队溯源流程详细整理

CloudCompare——泊松重建

8. Ribbon load balancing service call

character constants

Never use redis expired monitoring to implement scheduled tasks!

New specification of risc-v chip architecture

Calculate the distance between two points (2D, 3D)

RISC-V 芯片架构新规范

Detailed sorting of HW blue team traceability process
随机推荐
Hands on data analysis unit 3 model building and evaluation
Input text to automatically generate images. It's fun!
Wechat applet Registration Guide
Niuke challenge 53:c. strange magic array
虫子 STL string 下 练习题
网络远程访问的方式使用树莓派
[ahoi2005] route planning
Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
What is the use of index aliases in ES
Taishan Office Technology Lecture: four cases of using bold font
8.Ribbon负载均衡服务调用
Network remote access using raspberry pie
CloudCompare——泊松重建
Linear basis count (k large XOR sum)
Reprint - easy to use wechat applet UI component library
Zero basics of C language lesson 8: Functions
d的is表达式
C language ---getchar() and putchar()
Included angle of 3D vector
hands-on-data-analysis 第三单元 模型搭建和评估