Base statements for creating libraries, tables, and queries in MySQL

Source: Internet
Author: User

The creation of libraries, tables, and query statements in MySQL is very helpful for us to use the database in the future, this article is a summary of these basic statements, I hope it will help you

1. Create and delete databases

Creating a Database

mysql> CREATE DATABASE TestDB;

Mysql> CREATE database if not exists testdb;

Mysql> Create schema if not EXISTS student character set ' GBK ' collate ' gbk_chinese_ci ';

Delete Database

mysql> drop database TestDB;

2. Create and delete tables

CREATE TABLE [if not exists] Tb_name (col_name,col_definstion,constraint)

Create a table

Mysql> CREATE TABLE TB (ID int unsigned NOT NULL auto_increment primary Key,name char (20)

Not null,age tinyint not null);

Mysql> CREATE TABLE TB (ID int unsigned NOT NULL Auto_increment,name char (a) not null,age

Tinyint not null,primary key (ID));

mysql> CREATE DATABASE MyDB;

mysql> use MyDB;

Mysql> CREATE TABLE students (name char () not null,age tinyint Unsigned,gender char (1)

Not null);

Mysql> CREATE TABLE courses (ID tinyint unsigned not NULL Auto_increment primary

varchar (m) not null);

Mysql> CREATE TABLE courses (name char () not null,age tinyint Unsigned,gender char (1)

Not null); ---Identify the required number from a table and create it as a new table, but the properties of many fields do not exist and need to be redefined

Mysql> CREATE TABLE testcourses select * from courses where CID <=2;

With a different table as a template, create a new table, and the field's properties will still exist

Mysql> CREATE table test like courses;

Delete table: drop table tb_name;

mysql> drop table testcourses;

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.