Use of CREATE, USE, SHOW and DESCRIBE Commands in SQL

 Use of CREATE, USE, SHOW and DESCRIBE Commands in SQL

To demonstrate the use of "CREATE" command in SQL. The "CREATE " command is the most basic command in SQL. It helps to create a new Databases, Tables, Views , etc. We will go through all these things with example.

"CREATE DATABASE <db_name>"
This command is used to create a new SQL database. For example, If we are to create a database called expense_system then,

SQL Command: CREATE DATABASE expense_system;

Now let's try this with XAMPP server and create the database expense_system. If you click on shell in XAMPP then you will get a terminal to write the SQL command. But to execute the command in shell you should enter to the system with "mysql -u root -p" command. It is the default command. "-u" denotes the username and "-p" denotes the password which is empty. If you write "mysql -u root" then also you can get into the system.

In the given picture below you can see how to use the command.

create database

This is the command you need to enter at first to enter to the database.

create database

"SHOW DATABASES"

As you can see we use the "CREATE DATABASE expense_system;" command to create database. Just to see if the database is created or not we can use "SHOW DATABASES;" command. We will discuss more about in other chapters also. SHOW DATABASES command shows all the database created. In the given picture below you can see we successfully created a database.

show database

"USE COMMAND"

Also to access the database we just created. We have to use "USE COMMAND". It is very easy to use. you just have to write the command USE db_name;

SQL Command: USE expense_system;

Now with "CREATE" command we can also create tables. For tables we have to use "CREATE TABLE <tbl_name>" command. 

For example, let's create table "user" with its attributes user_id, email, phone. username, password in database we just created expense_system.

SQL Command:

CREATE TABLE user (

user_id INT PRIMARY KEY AUTO_INCREMENT,

email VARCHAR(45) NOT NULL,

phone BIGINT NOT NULL,

username VARCHAR(15) NOT NULL,

password VARCHAR(45) NOT NULL

);

create table

Now to confirm that we have created the table, you can use "SHOW TABLES" command in the terminal. As you can see in the image below that we have successfully created the table named "user" in expense_system database.

show tables

"DESCRIBE COMMAND"

Also if you have to check the attributes of database table "user" then "DESCRIBE USER" command comes in handy.

SQL Command: DESCRIBE user; 

Note: "user" is a table name.  

The image below will show you the result.

describe user

These are some basic use of CREATE, USE, SHOW AND DESCRIBE Commands in SQL.

Other blog links:







2 Comments

Previous Post Next Post