OneCompiler

IT EXAM ALL SQL COMMANDS

256

-- creating TABLE
CREATE TABLE EMPLOYEE (
empId INTEGER,
name TEXT,
dept TEXT,
city text
);
-- inserting values
INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales','mumbai');
INSERT INTO EMPLOYEE VALUES (0003, 'Dave', 'Accounting','delhi');
INSERT INTO EMPLOYEE VALUES (0004, 'Dave', 'Accounting','chennai');
INSERT INTO EMPLOYEE VALUES (0005, 'Dev', 'Accounting','gujarat');
INSERT INTO EMPLOYEE VALUES (0006, 'Dave', 'Accounting','uttar pradesh');
INSERT INTO EMPLOYEE VALUES (0007, 'Ava', 'Sales','bengaluru');
-- table structure
desc EMPLOYEE;

-- selecting on condition of equality
SELECT * FROM EMPLOYEE WHERE dept = 'Sales';
-- selecting on condition of greater than
select empId,dept from EMPLOYEE where empId>0000;
-- selecting unique values by eliminating duplicate values
select distinct name from EMPLOYEE;
-- simple calculations using select command
select 145652*20;
-- displaying system date
select curdate();
-- seting coloum alias
select empId,name,dept AS "employeeid" from EMPLOYEE;
-- selecting on range conditions
select * from EMPLOYEE where empId between 0001 and 0005;
-- manually adding primary key
alter table EMPLOYEE add PRIMARY key(empid);
-- updating existing database
update EMPLOYEE set name = 'dinesh' where name = 'dave';
select * from EMPLOYEE;
-- deleting a row
delete FROM EMPLOYEE where empId = 7;
select * from EMPLOYEE;
-- changing coloum name
alter table EMPLOYEE change empId employeeid int;
select * from EMPLOYEE;
-- deleting table if exist
drop table if exists students;
select * from EMPLOYEE;
-- no effect since students table does not exist
-- -- deleting EMPLOYEE table
drop table EMPLOYEE;
select * from EMPLOYEE;
-- all commands covered except some constraints