当前位置:网站首页>MySQL foundation 06 DDL
MySQL foundation 06 DDL
2022-07-03 01:12:00 【Super brother 1986】
DDL operation
DDL(Data Definition Language), Data definition language , Used to define database objects : database , surface , Column, etc. , For example, create 、 Delete 、 modify : database 、 Table structure, etc . This article mainly talks about mysql In the database DDL The use of language , Of course, this is different from sql The standard DDL It's in the same vein , Only the data types of specific databases are different .
1. Operating the database DDL, Include database view 、 Switch 、 Create and delete
First, the user login of the client , such as windows Of dos State, ,mysql -uxxx -pyyy,xxx and yyy They are user name and password . Of course , Before logging in, make sure mysql The service for has started .
View all databases of the user ,show databases;
Pay attention to the implementation of sql Your order needs a semicolon , Otherwise, some commands will be considered as line feed .
install mysql after , The system will automatically create some databases , Yes 4 individual , Respectively information_schema、mysql、performance_schema、test, It has 5 individual , among mydb1 It's my new .
It should be noted that , There is no need to modify or operate the databases created by these systems , Otherwise, it may cause mysql Use exception , Serious ash makes the database unusable .
The command to create the database is : create database Database name ;
The command to delete the database is :drop database Database name ;
Finally, the switching of database , The order is :use Database name ;
The above is the database DDL Common operations for
2.DDL Operation table , It mainly includes the creation of tables 、 Modification and deletion, etc . The modification of the table includes the addition and deletion of columns 、 Modify the column 、 Modify table name, etc .
First of all, let's talk about the operation of using morality to query all tables in the database , The order is :show tables;
Common statements for creating database
Query all databases
show databases;
Create database
create database dbname;
Using a database
use dbname;
Query all data tables
show tables;
Delete database
drop database dbname;
Table common statements
1、 Create an article
For example, a common name is emp Table of , The fields in the table contain 3 A field ,ename( full name ),hiredate( Date of dismissal )、sal( salary ), The field types are varchar(10)、data、int(2) Field types will be introduced later .
create table emp(ename varchar(10),hiredate date,sal decimal(10,2),deptno int(2));
see emp surface , The following information will be output .
desc emp;
Always say desc Command to view table definitions , But the input information is still not comprehensive .
show create table emp;
Processing can see SQL In the sentence , Processing can see that the table definition is unexpected , You can also see the watch engine( Storage engine )
2、 Deleted
Delete statement of table
drop table tablename;
3、 Revision article
3.1、 Modify the table type syntax as follows :
alter table emp modify ename varchar(20);
3.2、 Add table field
alter table emp add column age int(3);
3.3、 Delete table fields
alter table emp drop column age;
3.4、 Field modification name
alter table emp change ename username varchar(20);
3.5、 Modify the field arrangement Book sequence
For example, the new field is in birth Add to username after ;
alter table emp add birth date after username;
Modify fields deptno, Put it in the front .
alter table emp modify deptno int(3) first;
3.6、 Clear the table
truncate table emp;
边栏推荐
- 1038 Recover the Smallest Number
- 按键精灵打怪学习-回城买药加血
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- MySQL基础用法02
- Explain the basic concepts and five attributes of RDD in detail
- Basic use of sringcloud & use of component Nacos
- [AUTOSAR + IO Architecture]
- MongoDB系列之MongoDB常用命令
- 详解RDD基本概念、RDD五大属性
- matlab查找某一行或者某一列在矩阵中的位置
猜你喜欢
Rk3568 development board evaluation (II): development environment construction
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
[AUTOSAR XIII NVM]
MySQL
[C language] branch and loop statements (Part 1)
Asynchronous, email and scheduled tasks
Understanding and distinguishing of some noun concepts in adjustment / filtering
Excel calculates the difference between time and date and converts it into minutes
数据分析思维分析犯法和业务知识——分析方法(一)
Basic use of sringcloud & use of component Nacos
随机推荐
Solve the cache problem of reactnative using WebView
ROS2之ESP32简单速度消息测试(极限频率)
Every k nodes in the linked list are flipped
Matlab Doppler effect produces vibration signal and processing
Leetcode-241: designing priorities for operational expressions
Leetcode-871: minimum refueling times
[AUTOSAR II appl overview]
First hand evaluation of Reza electronics rz/g2l development board
[自我管理]时间、精力与习惯管理
【FPGA教程案例5】基于vivado核的ROM设计与实现
攻克哈希的基本概念与实现
Kivy教程大全之如何在 Kivy 中创建下拉列表
1038 Recover the Smallest Number
链表中的节点每k个一组翻转
[shutter] image component (cached_network_image network image caching plug-in)
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
基本远程连接工具Xshell
KingbaseES ALTER TABLE 中 USING 子句的用法
瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées