SQL Fundamentals

an anonymous user · February 23, 2021 · SQL
CREATE TABLE STUDENT(ROLL INTEGER(3),NAME VARCHAR2,CITY VARCHAR2,AGE NUMBER(2),CGPA NUMBER(3,2));
/*-----------------------------------------------------------*/
INSERT INTO STUDENT VALUES(101,'RAM','BHUBANESWAR',19,9.0);
INSERT INTO STUDENT VALUES(102,'HARI','BHUBANESWAR',NULL,6.7);
INSERT INTO STUDENT VALUES(103,'UDAY','JHARKHAND',20,8.97);
INSERT INTO STUDENT VALUES(104,'VIKAS','UTTAR PRADESH',19,8.5);
INSERT INTO STUDENT VALUES(105,'SWETA','RANCHI',19,9.2);
INSERT INTO STUDENT VALUES(106,'YOGESH','RAJASTAN',18,7.9);
INSERT INTO STUDENT VALUES(210,'SMRITI','DELHI',20,8.99);
INSERT INTO STUDENT VALUES(211,'SUDAM','CUTTACK',21,8.6);
INSERT INTO STUDENT VALUES(212,'VIKAS','KOLKOTA',23,5.98);
INSERT INTO STUDENT VALUES(165,'MANISH','',19,9.15);

/*1*/SELECT ROLL,NAME FROM STUDENT;
/*2*/SELECT * FROM STUDENT;
/*3*/SELECT DISTINCT CITY FROM STUDENT;
/*4*/SELECT NAME,AGE,AGE+4 AS 'GRADUATION AGE' FROM STUDENT;
/*5*/SELECT NAME||""||ROLL FROM STUDENT;
/*6*/SELECT NAME FROM STUDENT WHERE CITY='BHUBANESWAR';
/*7*/SELECT NAME FROM STUDENT WHERE CITY NOT IN('BHUBANESWAR');
/*8*/SELECT NAME FROM STUDENT WHERE NAME LIKE('S%');
/*9*/SELECT NAME,AGE FROM STUDENT WHERE AGE BETWEEN 20 AND 23;
/*10*/SELECT * FROM STUDENT WHERE CITY IS NULL;
/*11*/SELECT * FROM STUDENT ORDER BY AGE DESC;
/*12*/SELECT * FROM STUDENT WHERE AGE IS NOT NULL ORDER BY AGE ASC;
/*----------------------------------------------------------------*/
/*1*/ALTER TABLE STUDENT ADD(ADDRESS VARCHAR2(20));
SELECT * FROM STUDENT;
/*2*/ALTER TABLE STUDENT MODIFY(ROLL NUMERIC(3));
SELECT * FROM STUDENT;
/*3*/ALTER TABLE STUDENT DROP ADDRESS;
SELECT * FROM STUDENT;
/*4*/ALTER TABLE STUDENT RENAME ROLL TO ROLLNO;
SELECT ROLLNO,NAME FROM STUDENT;
/*5*/DESCRIBE STUDENT;
/*----------------------------------------------------------------*/
/*1*/UPDATE STUDENT SET NAME='RAHUL' WHERE ROLL=101;
SELECT NAME,ROLL FROM STUDENT;
/*2*/ALTER TABLE STUDENT ADD(BRANCH VARCHAR2(3));
UPDATE STUDENT SET BRANCH='IT';
SELECT * FROM STUDENT;
/*----------------------------------------------------------------*/
SELECT * FROM TAB;
SELECT table_name FROM user_tables;
SELECT ROWID,ROLL FROM STUDENT;
RENAME STUDENT TO STUD;
SELECT * FROM STUD;

Comments

Please sign up or log in to contribute to the discussion.