MySQL DLL Statement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.