SQL
SQL
-use hrm
-select * from emp;
________________________________________________________________
# To display databases in the mysql
--> show databases ;
# To create the new databases in mysql
--> Create database database_name ;
eg.
--> create database hrm;
hrm is the name of the database.
# To open database or use database
--> use database_name;
eg.
--> use hrm;
Now hrm database is open and we can create table in the database hrm.
# To check list of tables
--> show tables;
To create the table
--> create table table_name
( col_name1 data_type constraint,
col name2 data_type constraint,
.......);
eg.
create table dept (
dept_id int ,
dept_name char(25),
location char(10)
);
---------------------------------------------------------
#To remove or delete the table from the database
syntax :
drop table table_name ;
Solution==>
#create table emp (
emp_id int Primary Key,
emp_name char(20) not null,
designation char(20) not null,
basic_salary numeric(10,2) not null,
dept_id int
);
#TO VIEW ==> select * from emp; {* means all columns are selected}
# To view only id, name and designation ==> select emp_id,emp_name, designation
from emp,
# select dept_id, emp_name, basic_salary from emp;
Q> person having salary more than 20000 and less than 40000 but not equal to?
==> basic_salary > 20000 and basic_salary < 40000
# select * from emp where basic_salary between 20000 and 40000; ==. it will show
both the values
to view all data add "not " before between
# select distinct designation from emp;
# select max(basic_salary) from emp; {{to show maximum salary}}
# select min(basic_salary) from emp; {{to show minimum salary}}
# select sum(basic_salary) from emp; {{to show sum of salary}}
# select count (emp_id) from emp;
# Update command
It is used to modify the records of the table.
syntax:
Update table_name set field_name = value, field_name = value, ....
where...
eg.
update
# drop table_name; (to remove the table which will be not recovered)
# primary key
we cant enter the duplicate value in it.
# default key:
if we dont enter the value it will automatically displY THE default value.