当前位置:网站首页>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;
边栏推荐
- MySQL multi table joint deletion
- R language ggplot2 visual faceting, visual facet_wrap bar plot, using strip Text function customize the size of the strip of each facet title in the facet graph (cutimi
- Array and collection performance comparison
- 比较版本号
- [AUTOSAR twelve mode management]
- 数据分析思维分析犯法和业务知识——分析方法(一)
- matlab 多普勒效应产生振动信号和处理
- 测试右移:线上质量监控 ELK 实战
- Linear programming of mathematical modeling (including Matlab code)
- 【FPGA教程案例6】基于vivado核的双口RAM设计与实现
猜你喜欢

【无标题】
![[love crash] neglected details of gibaro](/img/d6/baa4b5185ddaf88f3df71a94a87ee2.jpg)
[love crash] neglected details of gibaro
![[overview of AUTOSAR three RTE]](/img/6a/0df33beb42f165af77a17b5d8b01e2.png)
[overview of AUTOSAR three RTE]

leetcode:701. 二叉搜索树中的插入操作【bst的插入】

Advanced pointer (I)

每日一题之干草堆的移动

Esp32 simple speed message test of ros2 (limit frequency)
![[shutter] image component (configure local GIF image resources | load placeholder with local resources)](/img/73/19e2e0fc5ea6f05e34584ba40a452d.jpg)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)

Win10 can't be installed in many ways Problems with NET3.5

安全运营四要素之资产、脆弱性、威胁和事件
随机推荐
On Fibonacci sequence
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
matlab 多普勒效应产生振动信号和处理
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
[AUTOSAR 11 communication related mechanism]
解决ReactNative使用webView存在缓存问题
正确甄别API、REST API、RESTful API和Web Service之间的异同
[AUTOSAR + IO Architecture]
Array and collection performance comparison
Leetcode-2115: find all the dishes that can be made from the given raw materials
信息熵的基础
Thank you for being together for these extraordinary two years!
Kivy教程大全之如何在 Kivy 中创建下拉列表
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
合并K个已排序的链表
Inversion de l'intervalle spécifié dans la liste des liens
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
1038 Recover the Smallest Number