MySQL learns a DDL (data definition language)

Source: Internet
Author: User
Tags naming convention

First, the specific installation of MySQL here is not much to say, there are many online. You can find it on the Internet, there are installed version and compressed version.

Second, verify that the database is installed successfully:

Under DOS command line enter: Mysql-u root-p (the default is the direct return on it, if you do not set the password)

If you set a password, you have to enter the password.

Will log on to MySQL, there is a message for MySQL.

Third,DDL: Data definition language

Description: What is DDL ? data definition Language; We know what it is, and then we should know what it does, right? I think we learn a lot of things when it is like this, first need to know what it is, and then need to know what it is used, and finally know how to use it? Of course, this is my personal understanding of the General affairs process at this stage.

Next, let's see what DDL does! role : The language used to describe the real-world entities to be stored in the database sounds like a bit of a mouthful, in fact, simply: Creating a database and table structure

Commonly used keywords: CREATE ALTER DROP TRUNCATE

Convention: Keyword lowercase, user-defined things all uppercase, multiple words, separated by an underscore.

Syntax: By default, statements are delimited by semicolons.

Capitalization problem: MySQL is not case-sensitive under window. Other systems are strictly case sensitive.


The common DDL operations are as follows:

1. Library operation

(1) create a database called Test1:

Create database TEST1; (Remember to end with a semicolon, of course, as much as possible to abide by our naming convention)

(2) See how many libraries are currently available:

show databases;

(3) View the database creation details

Show CREATE Database TEST1;

(4) Create a Test2 database that uses the GBK character set

Create DATABASE TEST2 character Set GBK;

(5) Create a TEST3 database that uses the GBK character set with proofing rules

Create DATABASE TEST3 character set GBK collategbk_chinese_ci;

(6) Delete the previously created TEST3 database

Drop database TEST3;

(7) View The database in the server, and modify the TEST2 character set to UTF8;

ALTER DATABASE TEST2 character set UTF8; (Pro, don't lose UTF-8 OH)

2. Table structure

(1) View the currently selected database

Select Database ();

(2) Select a database

Use TEST1;

Create an Employee table

CREATE TABLE EMPLOYEE (

ID int,

Namevarchar (100),

Gendervarchar (10),

BIRTHDAY date,

Entry_date DATE,

Jobvarchar (100),

SALARY Float (8,2),

RESUME Longtext

);

View table Structure

Desc EMPLOYEE;

An image column is basically added to the employee table above .

ALTER TABLE EMPLOYEE Add (IMAGE longblob);

Modify The job column so that it is a length of .

ALTER TABLE EMPLOYEE Modify Jobvarchar (60);

Delete the image column.

ALTER TABLE EMPLOYEE drop IMAGE;

The table name is changed to user.

Rename table EMPLOYEE to USER;

View all tables in the current library

Show tables;

Modify the table's character set to UTF8

ALTER TABLE USER character set UTF8;

Column name name modified to username

ALTER TABLE USER change NAME usernamevarchar (100);


This article is from the "Learning Notes" blog, so be sure to keep this source http://7298246.blog.51cto.com/7288246/1867460

MySQL learns a DDL (data definition language)

Related Article

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.