Home  >  Article  >  Database  >  Detailed explanation of examples of DDL statements

Detailed explanation of examples of DDL statements

零下一度
零下一度Original
2017-07-24 10:15:262139browse

2017-07-11 12:47:30

1 .Query the database under the current connection
SHOW DATABASES;

2.Create a new database
CREATE DATABASE [IF NOT EXISTS] java03 [CHARSET UTF8];

//CREATE DATABASE java03;

3. Delete a database
DROP DATABASE [IF EXISTS] JAVA03;

4. Set Defined encoding set

ALTER DATABASE java03 CHARACTER SET utf8;

##5. Enter the java03 databaseUSE java03 ;

6. Show all tables in the current databaseSHOW TABLES;

7. Create tableCREATE TABLE table name (
Column name 1 type,
Column name 2 type,
...
);

8. Print the creation statement of the tableSHOW CREATE TABLE table name

//show create table class;

9. View table structureDESC table name;

// desc class;

10. Delete tableDROP TABLE table name
;

11. Add columnsALTER TABLE table name ADD (column name 1 type, column name 2 type,...);

12 Modify column name typeALTER TABLE table name MODIFY column name type;

//ALTER TABLE student MODIFY classid char;
Change student table The classid column type in is changed to char type

13 Modify the column nameALTER TABLE table name CHANGE old column name new column name type;

//ALTER TABLE student CHANGE classid class char;
Change the classid in the student table to this Change the column name of a column to class

##14. Delete the column

ALTER TABLE table name DROP column Name;

//ALTER TABLE student DROP class;

Delete the class column in the student table

15. Modify the table name

ALTER TABLE old table name RENAME new table name;

/ /ALTER TABLE student RENAME s1 ;

Change the table name of the student table to s1

The above is the detailed content of Detailed explanation of examples of DDL statements. 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