MySQL DDL statements What is DDL, DML. DDL is data definition language, which is the operation on the database and table level, such as CREATE, ALTER, and DROP. DML is a data manipulation language, which means adding, deleting, modifying and checking data in a table, such as SELECT, UPDATE, INSERT and DELETE. Assume that there is a database lian_xi with tables user and orders; 1.1 Log in to the MySQL environment In the cmd window, enter mysql -u root -p to log in to the MySQL environment 1.2 View the database Show databases; 1.3 Using the Database Use database name; Use lian_xi; 1.4 Create a database Create database database name; Create database lian_xi; 1.5 Delete the database Drop database database name; Drop database lian_xi; 1.6 Create Table Create table table name( Notice: CREATE TABLE orders( `id` INT UNSIGNED AUTO_INCREMENT, `orders_title` VARCHAR(100) NOT NULL, `orders_price` DOUBLE NOT NULL, `create_date` DATE, PRIMARY KEY ( `id` ) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table constraints
1.7 Delete Table Drop table table name; Drop table user; 1.8 Modify the table and rename the table name Rename table original table name to new table name; Rename table user to user_table; Add a new column to the user table: add a column hobby, (comment is followed by 'comment' or 'description'. It needs to be enclosed in single quotes); Alter table user add column hobby varchar(100) comment 'hobby' not null; ALTER TABLE user_table ADD COLUMN hobby VARCHAR(100) NOT NULL COMMENT 'Hobby'; Add a comment to the table user_table [Personal Information Table], the comment needs to be enclosed in single quotes alter table user_table comment = 'Personal information table'; Delete columns Delete the user_table hobby column (Danger: Do not delete it at will) alter table user_table drop column hobby; Modify column name Alter table user change name username varchar(55); Modify column type Alter table user change name name char(4); Modify column type Alter table user modify name char(4); 1.9 Index Adding an index Add an index to the primary key id of the user table; create unique index ind_user_id on user(id); Delete index Delete the ind_user_id index of table user; drop index ind_user_id on user; For other MySQL articles, please see the following links MySQL DDL statements MySQL CRUD statements MySQL Aggregate Functions MySQL multi-table query END… This is the end of this article about the basic statements of MySQL data definition language DDL. For more relevant MySQL data definition language DDL content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Steps to purchase a cloud server and install the Pagoda Panel on Alibaba Cloud
>>: JavaScript setinterval delay one second solution
Preface: Lynis is a security audit and hardening ...
1. mpstat command 1.1 Command Format mpstat [ -A ...
Cerebro is an evolution of the Elasticsearch Kopf...
Debug branch During the normal development of a p...
It is not possible to use width and height directl...
Preface Tomcat is a widely used Java web containe...
About derived tables When the main query contains...
Table of contents 1. Understanding the stack stru...
Table of contents 1. Problems encountered 2. Idea...
First, start MySQL in skip-grant-tables mode: mys...
The find command is mainly used to find directori...
From handicraft design to graphic design to web de...
When rendering Markdown before, I used the previe...
This article example shares the specific code of ...
This article shares the specific code for randomi...