Home  >  Article  >  Database  >  DDL

DDL

PHP中文网
PHP中文网Original
2017-07-09 18:14:021385browse

#DDL--DATA DEFINITION LANGUAGE
#----------Library-----------------
#Create a database
CREATE DATABASE day19;
#Create a database encoded as utf8
CREATE DATABASE day191 CHARSET UTF8;

#Display all database names
SHOW DATABASES;

#View database creation information
SHOW CREATE DATABASE day191;
SHOW CREATE DATABASE day19;
SHOW CREATE DATABASE ex01;

#Delete the specified database
DROP DATABASE day191;

#View the database in use
SELECT DATABASE();

#Choose to use a database
USE day19;
#View the database in use
SELECT DATABASE();

#Display all tables in the library
SHOW TABLES;

#----------surface--------------
#Create table and add fields
CREATE TABLE abc(
aid INT PRIMARY KEY,
aname VARCHAR(20) NOT NULL UNIQUE,
age INT NULL);

CREATE TABLE abcd(
did INT PRIMARY KEY,
dname VARCHAR(20),
ddate DATE
);

#Show table structure
DESC abc;
DESC abcd;

#Delete table abcd
DROP TABLE abcd;
#Show all tables
SHOW TABLES;

#Modify table-add column
ALTER TABLE abc
ADD hobby VARCHAR(24) NULL DEFAULT '0';
#Show table structure
DESC abc;

#Modify table-delete column
ALTER TABLE abc
DROP hobby;
#Show table structure
DESC abc;

#Modify the data type and constraints of the column
ALTER TABLE abc
MODIFY aage VARCHAR(20);
DESC abc;

#Modify field name
ALTER TABLE abc
CHANGE age age DOUBLE(3,2) NOT NULL DEFAULT 0;
DESC abc;

#Modify table name
RENAME TABLE abc TO bbc;
DESC bbc;

RENAME TABLE BBC TO ABC;
DESC abc;

The above is the detailed content of DDL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn