Wednesday, 15 March 2017

SQL DATABASE


SQL CREATE Database

The SQL CREATE DATABASE statement is used by a developer to create a database.
Let's see the syntax of SQL CREATE DATABASE:
CREATE DATABASE database_name;  
If you want to add tables in that database, you can use CREATE TABLE statement.

Create Database in MySQL

In MySQL, same command is used to create a database.

CREATE DATABASE database_name;  

Create Database in Oracle

You don't need to create database in Oracle. In Oracle database, you can create tables directly.
You can also rename, drop and select database that is covered in next pages.

We should always remember that database name should be unique in the RDBMS.


SQL DROP Database

SQL DROP statement is used to delete or remove indexes from a table in the database.
If you want to delete or drop an existing database in a SQL schema, you can use SQL DROP DATABASE
Let's see the syntax of SQL DROP DATABASE:
1.    DROP DATABASE database_name;  

If you delete or drop the database, all the tables and views will also be deleted. So be careful while using this command.

 

 

SQL RENAME Database

SQL RENAME DATABASE is used when you need to change the name of your database. Sometimes it is used because you think that the original name is not more relevant to the database or you want to give a temporary name to that database.

Let's see how to rename Mysql and SQL Server databases.

Rename MySQL database

To rename the mysql database, you need to follow the following syntax:
1.    RENAME DATABASE old_db_name TO new_db_name



SQL SELECT Database
In MySQL database, you need to select a database first before executing any query on table, view etc. To do so, we use following query:
1.    USE DATABASE database_name;  

In oracle, you don't need to select database.

No comments:

Post a Comment