当前位置:网站首页>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;
边栏推荐
- [untitled]
- Cut point of undirected graph
- In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
- Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
- matlab查找某一行或者某一列在矩阵中的位置
- [overview of AUTOSAR four BSW]
- [AUTOSAR + IO Architecture]
- Asynchronous, email and scheduled tasks
- 【FPGA教程案例5】基于vivado核的ROM设计与实现
- Draw love with go+ to express love to her beloved
猜你喜欢
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
Key detection and sinusoidal signal output developed by Arduino
研发一款国产ARM智能边缘计算网关需要什么
Merge K sorted linked lists
用Go+绘制爱心给心爱的她表白
瑞萨电子RZ/G2L开发板上手评测
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
[C language] branch and loop statements (Part 1)
寻找标杆战友 | 百万级实时数据平台,终身免费使用
Basic use of sringcloud & use of component Nacos
随机推荐
比较版本号
Key wizard play strange learning - front desk and Intranet send background verification code
2022.2.14 resumption
Assets, vulnerabilities, threats and events of the four elements of safe operation
Leetcode-849: maximum distance to the nearest person
Specified interval inversion in the linked list
[AUTOSAR + IO Architecture]
mysql 多表联合删除
机器学习术语
Linear programming of mathematical modeling (including Matlab code)
电话网络问题
[case sharing] let the development of education in the new era advance with "number"
[overview of AUTOSAR three RTE]
异步、郵件、定時三大任務
excel表格计算时间日期的差值,并转化为分钟数
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
Daily topic: movement of haystack
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
【FPGA教程案例5】基于vivado核的ROM设计与实现
How to convert Quanzhi a40i/t3 to can through SPI