当前位置:网站首页>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;
边栏推荐
- 无向图的割点
- Leetcode-241: designing priorities for operational expressions
- Leetcode-934: the shortest Bridge
- Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
- What is needed to develop a domestic arm intelligent edge computing gateway
- Foundations of data science is free to download
- 链表中的节点每k个一组翻转
- mysql 多表联合删除
- The difference between tail -f, tail -f and tail
- Excel removes the data after the decimal point and rounds the number
猜你喜欢
随机推荐
Rk3568 development board evaluation (II): development environment construction
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
465. DFS backtracking of optimal bill balance
攻克哈希的基本概念与实现
Advanced pointer (I)
Key wizard play strange learning - multithreaded background coordinate recognition
Assets, vulnerabilities, threats and events of the four elements of safe operation
Linear programming of mathematical modeling (including Matlab code)
leetcode:701. Insertion in binary search tree [BST insertion]
[untitled]
Esp32 simple speed message test of ros2 (limit frequency)
[AUTOSAR eight OS]
Daily topic: movement of haystack
Explain the basic concepts and five attributes of RDD in detail
Solve the cache problem of reactnative using WebView
[自我管理]时间、精力与习惯管理
JS inheritance and prototype chain
The difference between relational database and non relational database
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0