当前位置:网站首页>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 .
边栏推荐
- 虫子 STL string上
- Go language - pipeline channel
- Svn commit error after deleting files locally
- Calculate the distance between two points (2D, 3D)
- 爱可可AI前沿推介(6.26)
- Educational Codeforces Round 117 (Rated for Div. 2)E. Messages
- Bucket of P (segment tree + linear basis)
- Linear basis
- 9 articles, 6 interdits! Le Ministère de l'éducation et le Ministère de la gestion des urgences publient et publient conjointement neuf règlements sur la gestion de la sécurité incendie dans les établ
- 微信小程序注册指引
猜你喜欢

7.consul service registration and discovery

使用 Performance 看看浏览器在做什么

Firewall introduction

Stream常用操作以及原理探索

33. Use rgbd camera for target detection and depth information output

Zero basics of C language lesson 7: break & continue

Network remote access using raspberry pie

VTK 圆柱体的生成与渲染

Win10 home vs pro vs enterprise vs enterprise LTSC

2021-10-18 character array
随机推荐
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
Hands on data analysis unit 3 model building and evaluation
免费的机器学习数据集网站(6300+数据集)
永远不要使用Redis过期监听实现定时任务!
Reprint - easy to use wechat applet UI component library
9项规定6个严禁!教育部、应急管理部联合印发《校外培训机构消防安全管理九项规定》
Select tag - uses the default text as a placeholder prompt but is not considered a valid value
[cqoi2015] task query system
Bucket of P (segment tree + linear basis)
[path of system analyst] Chapter 15 double disk database system (database case analysis)
[ahoi2005] route planning
Detailed sorting of HW blue team traceability process
In insect classes and objects
Exercise set 1
The most critical elements of team management
虫子 STL string 下 练习题
Postman自动化接口测试
虫子 内存管理 下 内存注意点
Linear basis
Global variable vs local variable