Learn "MYSQL" course, date 2017.4.25-2017.4.30

Source: Internet
Author: User

To display the database:

SHOW DATABASES database_name;

To create a database:

CREATE DATABASES database_name;

To delete a database:

DROP DATABASE database_name;

To create a data table:

CREATE table< Table name >

(

Field name 1, data type [column-level constraint] [default],

);

Cases:

CREATE TABLE TB1

(ID INT (11),

NAME VARCHAR (20));

Primary key: Field name data type PRIMARY key[default value];

Cases:

CREATE TABLE TB1

(ID INT (one) PRIMARY KEY,

NAME VARCHAR (20));

Or:

CREATE TABLE TB1

(ID INT (11),

NAME VARCHAR (20)

PRIMARY KEY (ID));

FOREIGN key:

[constraint< foreign key Name >] FOREIGN KEY field name 1[field Name 2]

preferences< primary Table name > Primary key column 1[primary key column 2]

Example: (Associating DeptID as a foreign key to Tb_2 's primary key ID)

CREATE TABLE tb_1

(

ID INT (one) PRIMARY KEY,

Name VARCHAR () not NULL (non-NULL),

Location VARCHAR (50)

);

CREATE TABLE tb_2

(

ID INT (one) PRIMARY KEY,

Name VARCHAR (20),

DeptID INT (11),

CONSTRAINT tb_1 FOREIGN KEY (deptid) REFERENCES tb_2 (id));

Set the property value of the table to automatically increase:

Field name data type Auto_increment

Cases:

ID INT (one) PRIMARY KEY auto_increment,

Modify Table Name:

ALTER table< Old table name >RENAME[TO]< new table name >

ALTER TABLE tb_1 RENAME tb_dept;

Modify Table Contents:

ALTER table< table name >MODIFY< field name >< data type >

ALTER TABLE tb_1 MODIFY name VARCHAR (30);

Learn "MYSQL" course, date 2017.4.25-2017.4.30

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.