当前位置:网站首页>MySQL of database -- Fundamentals
MySQL of database -- Fundamentals
2022-04-23 09:20:00 【King_ nul】
MySQL database
Catalog
3、 ... and 、 The management of the table
Four 、 General database building table writing method
5、 ... and 、 Replication of tables
One 、 summary :
Database installation : Database installation tutorial
Use as much as possible MySQL5.7 And other commonly used versions , There are many inconsistencies between the new version and the old version , For the convenience of practice, please choose the common version .
DDL(Data Definition Language): Data definition statement , For libraries and The creation of a table 、 modify 、 Delete .
DDL Used to define the structure of the database , Such as creating 、 Modify or delete Database objects , Includes the following SQL sentence :
CREATE TABLE: Create database tables
ALTER TABLE: Change table structure 、 add to 、 Delete 、 Modify column length
DROP TABLE: Delete table
IF EXISTS It is only used for deleting and creating libraries and tables
Two 、 Library management
1、 Database creation
grammar :
CREATE DATABASE Library name ;
Create a database using fault tolerance judgment ( Determine whether the database exists , If any, create after deletion , If there is no direct creation ):
mysql> create database if not exists mysqld;
Query OK, 1 row affected, 1 warning (0.24 sec)Change the library name (8.0 Later versions do not support the use of )
RENAME DATABASE book TO The name of the new library ;2、 View the system default character set
mysql> show variables like "%char%";
+--------------------------+-----------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | F:\Tools\mysqin\share\charsets\ |
+--------------------------+-----------------------------------+
8 rows in set, 1 warning (0.19 sec)3、 Modify database character set
mysql> alter database mysqld character set gbk;
Query OK, 1 row affected (0.20 sec)4、 Delete database ( If it exists )
mysql> DROP DATABASE IF EXISTS mysqld;
Query OK, 0 rows affected (0.25 sec)
3、 ... and 、 The management of the table
1、 The creation of a table
grammar :
CREATE TABLE Table name (
Field 1 Field type 【( length ) constraint 】,
Field 2 Field type 【( length ) constraint 】,
Field 3 Field type 【( length ) constraint 】,
Field name Field type 【( length ) constraint 】
);Fault tolerant creation :
# Case study 1: Create table book
CREATE TABLE IF EXISTS book(
id int(5),# Book number
bName varchar(20),# Title
price double(2),# Price
authorId int(5),# author id
publishDate datetime # Publication date
);# Case study 2: Create table author
CREATE TABLE 【IF EXISTS】 book(
id int(5),
au_Name varchar(20),
nation varchar(10)
);2、 The modification of table
grammar :
ALTER TABLE Table name Change column names | Modify column type | Add columns | Delete column | Modify the name of the table 【COLUMN】 Name 【 constraint 、 type 】;
ALTER TABLE Table name CHANGE|MODIFY|ADD|DROP|RENAME 【COLUMN】 Name 【 constraint 、 type 】;modify :
① Name
ALTER TABLE Table name CHANGE 【COLUMN】 Old column names New column names New field type ;
② Column types and constraints
ALTER TABLE Table name MODIFY 【COLUMN】 Old column names New field type ;
③ Add new column
ALTER TABLE Table name ADD 【COLUMN】 New column names New field type ;
④ Delete column
ALTER TABLE Table name DROP 【COLUMN】 Name ;
⑤ Modify the name of the table
ALTER TABLE Table name RENAME TO 【COLUMN】 The new name of the table ;3、 The deletion of the table
DROP TABLE IF EXISTS Table name ;
SHOW TABLES; # View all tables in the current database
Four 、 General database building table writing method
DROP DATABASE IF EXISTS Old library name ;
CREATE DATABASE The name of the new library ;
DROP TABLE IF EXISTS The old name of the table ;
CREATE TABLE The new name of the table ();
5、 ... and 、 Replication of tables
# Just copy the structure of the table
CREATE TABLE copy LIKE book;# You can copy the structure and data content of the table
CREATE TABLE copy2
SELECT * FROM book;
# Copy only part of the data
CREATE TABLE copy3
SELECT id,name
FROM book
WHERE name=" Chunshang village tree ";
# Copy only part of the table structure
CREATE TABLE copy4
SELECT id,name
FROM book
WHERE 0;
summary : The creation and modification of the basic library is relatively simple , Focus on the syntax and keywords of the modified part and the keywords when creating the table , Later, when other parts are published, they will write one by one , The content is not very comprehensive , After simple study, go deep .
版权声明
本文为[King_ nul]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230629527694.html
边栏推荐
- Learn FPGA (from Verilog to HLS)
- Applet error: cannot read property'currenttarget'of undefined
- Flink SQL realizes the integration of stream and batch
- STM32 and FreeRTOS stack parsing
- Wechat applet catchtap = "todetail" event problem
- How to render web pages
- js 原型链的深入
- Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
- SAP 101K 411k inventory change
- Brush classic topics
猜你喜欢

Chapter VIII project stakeholder management of information system project manager summary

Kettle实验 (三)

搞不懂时间、时间戳、时区,快来看这篇

Distributed message oriented middleware framework selection - Digital Architecture Design (7)

node安装

Failed to download esp32 program, prompting timeout

#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
![[SQL Server fast track] view and cursor of database](/img/2c/8edd92ecef11932c982db56af76c3f.png)
[SQL Server fast track] view and cursor of database

501. Mode in binary search tree

Pctp test experience sharing
随机推荐
Leetcode-199 - right view of binary tree
[Luke V0] verification environment 2 - Verification Environment components
NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
About CIN, scanf and getline, getchar, CIN Mixed use of getline
kettle实验
Brush classic topics
DJ music management software pioneer DJ rekordbox
GoLand debug go use - white record
成功的DevOps Leader 应该清楚的3个挑战
Multi view depth estimation by fusing single view depth probability with multi view geometry
How to render web pages
Employee probation application (Luzhou Laojiao)
Go language self-study series | golang nested structure
2D 01 Backpack
Canary publishing using ingress
MySQL小練習(僅適合初學者,非初學者勿進)
Project upload part
Matlab draw five-star red flag
STM32 and FreeRTOS stack parsing
Applet error: cannot read property'currenttarget'of undefined
