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;