SQL Code

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

SHOW DATABASES;

-- create database
CREATE DATABASE NITHI;
DROP DATABASE NITHI;
DROP SCHEMA IF EXISTS NITHI;
USE NITHI;
SHOW TABLES;

-- create tables
CREATE TABLE STUDENT(
id int primary key,
name varchar(30),
gpa decimal(3,2)
);
describe student;

-- alter values
alter table student add department varchar(10);
alter table student drop department;

-- insert values
insert into student values(1,"kavya",7.85);
insert into student values(2,"mythu",8.39);
insert into student values(3,"mouni",7.6);
insert into student values(4,"youga",8.2),(5,"nithi",7.65);
insert into student(id,name) values(6,"jai");
select * from student;
select id from student;
select distinct name from student;
select count(distinct name) from student;

-- WHERE ,FILTER
USE NITHI;

CREATE TABLE EMPLOYEE(


ID INT PRIMARY KEY,NAME VARCHAR(30),JOB VARCHAR(20),SALARY INT);
DESCRIBE EMPLOYEE;
INSERT INTO employee VALUES(1,'Ram','ADMIN',1000000);
INSERT INTO employee VALUES(2,'Harini','MANAGER',2500000);
INSERT INTO employee VALUES(3,'George','SALES',2000000);
INSERT INTO employee VALUES(4,'Ramya','SALES',1300000);
INSERT INTO employee VALUES(5,'Meena','HR',2000000);
INSERT INTO employee VALUES(6,'Ashok','MANAGER',3000000);
INSERT INTO employee VALUES(7,'Abdul','HR',2000000);
INSERT INTO employee VALUES(8,'Ramya','ENGINEER',1000000);
INSERT INTO employee VALUES(9,'Raghu','CEO',8000000);
INSERT INTO employee VALUES(10,'Arvind','MANAGER',2800000);
INSERT INTO employee VALUES(11,'Akshay','ENGINEER',1000000);
INSERT INTO employee VALUES(12,'John','ADMIN',2200000);
INSERT INTO employee VALUES(13,'Abinaya','ENGINEER',2100000);

SELECT * FROM EMPLOYEE


WHERE NAME="RAMYA";

SELECT NAME,JOB FROM EMPLOYEE


WHERE NAME<>"RAMYA";

SELECT * FROM EMPLOYEE


WHERE SALARY>2800000 AND JOB = "MANAGER";

SELECT * FROM EMPLOYEE


WHERE JOB="HR" OR JOB="MANAGER";
-- OR BETTER QUERY
SELECT * FROM EMPLOYEE
WHERE JOB IN ("HR","MANAGER") AND SALARY=3000000;

SELECT * FROM EMPLOYEE


WHERE JOB NOT IN ("HR");

SELECT * FROM EMPLOYEE


WHERE SALARY BETWEEN 2000000 AND 3000000;

SELECT * FROM EMPLOYEE


LIMIT 5;

-- LIKE- FILTERED BY PATTERN EG: NAME STARTING WITH A


-- WILDCARD %(0 OR MORE CHARECTERS),_ (ONE CHAR)

SELECT*FROM EMPLOYEE
WHERE NAME LIKE 'A%';
SELECT*FROM EMPLOYEE
WHERE NAME LIKE 'A%A';
SELECT*FROM EMPLOYEE
WHERE NAME LIKE '%I';
SELECT*FROM EMPLOYEE
WHERE NAME LIKE '__I%'; -- I SHOULD BE IN 3RD PLACE
-- \% % IS TAKEN AS A CHAR

-- UPDATE
UPDATE EMPLOYEE
SET JOB ="ANALYST"
WHERE JOB ="ENGINEER";

You might also like