Use of CREATE, USE, SHOW and DESCRIBE Commands in SQL
This is the command you need to enter at first to enter to the 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.
"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
);
"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.
These are some basic use of CREATE, USE, SHOW AND DESCRIBE Commands in SQL.Other blog links:
😍
ReplyDeletenice work
ReplyDelete