You are on page 1of 4

create database IBM_DB as perm=500000 spool =

500000;
grant all on IBM_DB to twm;

/* SYNTAX FOR CHECKING CURRENT DATABASE*/


select database;

/* SYNTAX FOR CHANGING THE DB*/


database IBM_DB;
create table demo(id int,name varchar(10));

/* SET TABLE*/
create set table DEMO_SET(id int,name varchar(10));
insert into DEMO_SET values(1,'ARAVIND');
select * from DEMO_SET;
insert into DEMO_SET values(1,'ARAVIND');

/* MULTISET TABLE*/
create multiset table DEMP_MS(id int,name varchar(10));
insert into DEMP_MS values(1,'ARAVIND');
select * from DEMP_MS;
insert into DEMP_MS values(1,'ARAVIND');

show table DEMP_MS;

/* VOLATILE TABLE*/
create volatile table demo_volatile(id int,name
varchar(10));
create volatile table demo_volatile1(id int,name
varchar(10)) ON COMMIT PRESERVE ROWS;
insert into DEMO_volatile1 values(1,'ARAVIND');
select * from DEMO_VOLATILE1;

/* GLOBAL TEMPORARY TABLE*/


create global temporary table demo_gbl(id int,name
varchar(10));
create global temporary table demo_gbl1(id int,name
varchar(10)) ON COMMIT PRESERVE ROWS;
insert into DEMO_GBL1 values(1,'ARAVIND');
select * from demo_gbl1;

/* DDL STATEMENTS*/

-- CREATE TABLE:
create table employee(empno int,ename varchar(10),sal
int);
--ALTER COMMAND WITH SPECIFIC OPERATIONS:
-- ADD COLUMN:
alter table employee add job varchar(20);
-- MODIFY THE EXISTING DATATYPE:
alter table employee add job varchar(30);
--RENAME A EXISTING COLUMN OF TABLE:
alter table employee rename sal to salary;
--DROPPING AN EXIXTING COLUMN:
alter table employee drop salary;
--RENAME TABLE:
rename table employee to emp;
rename table emp to employee;
--DML COMMAND:
--INSERT:
insert into employee values(1,'ARAVIND','MANAGER');
insert into employee values(2,'BALAJI','VP');
insert into employee values(3,'CHANDHRU','KING');
insert into employee values(4,'DINESH','PRESIDENT');
insert into employee values(5,'AZEEM','DPTMANAGER');
select * from employee;
--COPY OF A TABLWE WITH DATA:
create table emp_test as(select * from employee) WITH
DATA;
select * from emp_test;
--COPY OF A TABLE WITH NO DATA:
create table emp_test1 as(select * from employee) WITH
NO DATA;
select * from emp_test1;
--TRUNCATE TABLE RECORS:
delete emp_test all;
--DROP TABLE:
DROP table emp_test1;

--DML COMMANDS:
-- CREATE TABLE:
create table employee1(empno int,ename varchar(10),sal
int);
insert into employee1 values(1,'DINESH',1000);
insert into employee1 values(2,'RAMESH',1200);
insert into employee1 values(3,'RAKESH',1500);
select * from employee1;
--UPDATE RECORD OF A TABLE:
update employee1 set sal = sal+500 where empno = 3;
--DELETE A RECORD:
delete from employee1 where empno = 3;

-- WORKING WITH OPERATORS:


--ARITHMETIC:

select * from employee1;

select empno,ename,sal,sal+500 as tot_sal from


employee1;

--IN /NOTIN /BETWEEN/NOTBETWEEN


select * from employee1 where empno NOT IN(1,2);
select * from employee1 where sal between 1000 and
2000;
select * from employee1 where sal IS NULL;
select * from employee1 where sal IS NOT NULL;
select * from employee1 where ename LIKE 'R%';
select * from employee1 where ename LIKE '%ESH';

You might also like