Tags: mysql database/dba/Delete database tables
Overview
Because there are some things, from the publication of an article to the middle of the current interval of several months, in the following time will be published on some of the MySQL articles, from the base to the optimization of the final to management, welcome to the discussion.
Body
Create a database
CREATE DATABASE DBNAME;
Deleting a database
DROP DATABASE DBNAME;
Show All Tables
Show tables;
Create a table
CREATE TABLE TABLENAME (clumn clu_len)
CREATE TABLE INT(tennotNULLVARCHAR); -- defining the int type in MySQL syntax you can add the length of the field type after the parentheses, if not the length of int (11).
Self-increment column (auto_increment)
CREATE TABLE AI (ID INT auto_increment not NULL PRIMARY KEY);
List table Definitions
DESC TABLE;
View statements that create a table
Grammar show CREATE TABLE tablename;
TABLE USER \g;
Change table name
ALTER talbe tablename RENAME new_tablename
modifying field types
ALTER TABLE [COLUMN] [First| After Col_name]-- Modify the field name (The new field must be with the field type)
Rename Field
ALTER TABLE [COLUMN] [first| After Col_name]
Add Field
--GrammarALTER TABLETableNameADD [COLUMN]Column_definition[First | After Col_name]--Add a default Value fieldALTER TABLE User ADDAgeINT not NULL DEFAULT 0;
---self-increment
Auto_increment
Add the default value in MySQL cannot be preceded with ' () ', if the shape field is a direct space plus the value to be set, if the character field is a single quote ', this is different from SQL Server
Delete a field
ALTER TABLE DROP [COLUMN] col_name
Delete a table
DROP TABLE TableName
Summary
The DDL statement about MySQL is relatively simple, with some details on the syntax, and no syntax to remember.
If the article is helpful to everyone, please help me to recommend, thank you!!!
Note: pursuer.chen Blog:http://www.cnblogs.com/chenmh This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly to the link, otherwise reserves the right to hold responsibility. Welcome to the exchange of discussions |
MySQL DLL Statement