当前位置:网站首页>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 .
边栏推荐
猜你喜欢

嵌入式virlog代码运行流程

Wechat applet -picker component is repackaged and the disabled attribute is added -- below

Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them

Wechat applet Registration Guide

Create your own cross domain proxy server

Included angle of 3D vector

Input text to automatically generate images. It's fun!

ThreadLocal giant pit! Memory leaks are just Pediatrics

ThreadLocal巨坑!内存泄露只是小儿科...

2021-10-09
随机推荐
虫子 类和对象 中
Wechat applet Registration Guide
Range of types
GO语言-管道channel
It is better and safer to choose which securities company to open an account for flush stock
2021-10-09
Global variable vs local variable
Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value
同花顺股票开户选哪个证券公司是比较好,比较安全的
网络远程访问的方式使用树莓派
hands-on-data-analysis 第三单元 模型搭建和评估
Gee - Global Human Settlements grid data 1975-1990-2000-2014
Input text to automatically generate images. It's fun!
Insect operator overloaded a fun
Solutions to the failure of last child and first child styles of wechat applet
Niuke challenge 48 e speed instant forwarding (tree over tree)
Here document interaction free and expect automatic interaction
Awk tools
ThreadLocal巨坑!内存泄露只是小儿科...
虫子 内存管理 上