Database management SQL--

surroundings

  DBMS:MySQL 8.0.17

  Tools: Navicat Premium 11.2.16

Database Creation

  Syntax: the CREATE DATABASE <database name>;

  Create a database school: CREATE DATABASE school;

  You can see, the console displays successful execution.

  

  Indeed successfully created the database.

  

  Create a database school again and found the console display statement error, display "school" database already exists, can not be created again.

  

  In other words, the database can not be repeated to create.


  In order to ensure that no mistakes when you create a database, you can determine whether the same name exists in the database, create the database if it does not exist.

  Syntax: the CREATE DATABASE IF the NOT EXISTS <database name>;

  The statement read: CREATE DATABASE IF NOT EXISTS school;

  Implementation of the results:

  

Delete Database

  Syntax: DROP DATABASE <database name>;

  Delete Database school: DROP DATABASE school;

  You can see, the console displays successful execution.

  

  Delete database school again and found the console display statement error, display "school" database does not exist, it can not be deleted again.

  

  In other words, the database can not be repeated deleted.


  To ensure that the database can not go wrong when you delete, you can determine whether the database exists, if it exists delete the database.

  Syntax: DROP DATABASE IF EXISTS <database name>;

  The statement read: DROP DATABASE IF EXISTS school;

  Implementation of the results:

  

Database View

  Syntax: SHOW DATABASES ;

  

Database switch

  Operations on the data, and create basic tables, views, etc. are carried out within the database, you need to switch to the specified database to perform the next operation.

  Syntax: the USE <database name>;

  Switching into the database school: USE school;

  You can see, the console displays successful execution.

  

Guess you like

Origin www.cnblogs.com/lqkStudy/p/11462410.html