RDBMS (SQL QUERY DATABASE) BASIC CODE ON CREATE DATABASE, CREATE TABLE AND ALTER TABLE

RDBMS (SQL QUERY DATABASE) BASIC CODE ON CREATE DATABASE, CREATE TABLE AND ALTER TABLE

First just let me explain what is RDMS ?

ANS: RDBMS is basically a Relational Database Management System where we can create, insert, modify, alter and delete the table.

Now the next question comes what is Database?

ANS: Database is basically a structured or organized way of collection of data in a table format including rows and columns. Database can be of any type like employee's data, student's data, company's data, etc. Like as in excel we put the data in row and column wise that also we called it as database.

Now again the question comes what is SQL?

Ans: SQL is the Structured Query Language which basically manages the relational database.

Now from this one last question comes what is query?

Ans: Query we can say it the request which is made by the users to store all the data in database in table format in row and column wise. For Ex: create table `Employees`(emp_id int, name varchar(100), email varchar(100), salary decimal(10,2), joining_date date)

NOTE: As we know that DBMS(Database Management System) is not a case sentitive language so here we can write create database or create table in upper case also or in lower case also, but it won't affect in any way neither it will throw any errors for upper case or lower case as it's not a case- sensitive language.

1) Write an SQL query to create a database named EmployeeDB.

Ans: create database `EmployeeDB`

NOTE: (`) and (`) this symbol is referred to as backtick open and backtick close.

2) Create a table named Employees with the following columns:
- emp_id (INT)
- name (VARCHAR(100))
- email (VARCHAR(100))
- salary (DECIMAL(10,2))
- joining_date (DATE)

Ans: create table `Employees`(emp_id int, name varchar(100), email varchar(100), salary decimal(10,2), joining_date date)
                                                     Here emp_id should obviously be integer type because emp_id always becomes in numbers, name should obviously be variable character type because name is always a character, email also should be variable character type because email consist of character, number and @, salary should 
be decimal type because whenever any body ask us about salary or package we say it as 8.5 LPA or 9.5LPA, etc so it of decimal type and joining_date should always be date itself.

3) Add a new column phone_number (VARCHAR(15)) to the Employees table.

Ans: alter table `Employees` add column `phone_number` varchar(15) 
                                                Here phone_number should be variable character type because phone number should be always of limited digits that phone number should always be either of 8 digits or 10 digits. Like for telephone it's 8 digits but for mobile it's 10 digits which starts with the country code +91. Nowadays 8 digits telephone is obsolete. So, phone_number should be of variable character type. 

4) Rename the column salary in Employees table to monthly_salary.

Ans: alter table `Employees` change column `salary` `monthly_salary` decimal(10,2).

After writing the query in phpMyAdmin => SQL we need to click on GO button below to create database, create table, alter table, modify table or drop table. For your information drop table or drop database is basically we can called it as delete table or delete database. 


We can write the query in phpMyAdmin => SQL or in phpMyAdmin => "Edit inline" as shown in image below.








  







Comments