当前位置:网站首页>MySQL-DDL

MySQL-DDL

2022-06-21 11:47:00 Jue Niu thunder plough hot blade

/* DDL(Data Definition Language), Data definition language , The language section includes the following : 1. Common operations on Database  2. Common operations on table structure  3. Modify table structure  */

#  View all databases 
show databases;

#  Create database 
# create database db;
# if not exists: Optional operation , Create... If it doesn't exist 
create database if not exists db;

#  Select database to use 
use db;

#  Delete database 
# drop database db;
# if exists: Optional operation , Delete... If it exists 
drop database if exists db;

#  Modify database code 
alter database db character set utf8;

#  Create table 
create table if not exists student
(
    sid      int,
    name     varchar(20),
    gender   varchar(10),
    age      int,
    birthday date,
    address  varchar(20),
    score    double
);


#  View all tables in the current database 
show tables;
#  View the creation statement of the specified table 
show create table student;
#  View table structure 
desc student;
#  Delete table 
drop table if exists student;


#  Modify table structure 
#  Add columns 
alter table student
    add dept varchar(20);

#  Change column name and type 
alter table student
    change dept department varchar(30);

#  Delete column 
alter table student
    drop department;

#  Modify the name of the table 
rename table student to stu;

原网站

版权声明
本文为[Jue Niu thunder plough hot blade]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211146382048.html