SQL Query Interview Questions

Table of Contents

SQL Union

81. Select First_Name,LAST_NAME from employee table as separate rows?

select FIRST_NAME from EMPLOYEE union select LAST_NAME from EMPLOYEE;

82. What is the difference between UNION and UNION ALL?

Both UNION and UNION ALL are used to combine the results of two similar queries. The only difference between these two is : UNION will eliminate duplicate records in the result set while UNION ALL will include all duplicate rows too.

SQL Table Scripts

83. Write create table syntax for employee table?

CREATE TABLE EMPLOYEE (
EMPLOYEE_ID NUMBER,
FIRST_NAME VARCHAR2(20 BYTE),
LAST_NAME VARCHAR2(20 BYTE),
SALARY FLOAT(126),
JOINING_DATE TIMESTAMP (6) DEFAULT sysdate,
DEPARTMENT VARCHAR2(30 BYTE) );

84. Write Syntax for dropping EMPLOYEE table?

DROP table employee;

85. Write syntax to set EMPLOYEE_ID as primary key in employee table?

ALTER TABLE EMPLOYEE ADD CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EMPLOYEE_ID);

86. Write syntax to set 2 fields (EMPLOYEE_ID,FIRST_NAME) as primary key in employee table?

ALTER TABLE EMPLOYEE add CONSTRAINT
EMPLOYEE_PK PRIMARY KEY(EMPLOYEE_ID,FIRST_NAME);

87. Write syntax to drop primary key on employee table?

ALTER TABLE EMPLOYEE DROP CONSTRAINT EMPLOYEE_PK;

88. Write Sql Syntax to create EMPLOYEE_REF_ID in INCENTIVES table as foreign key with respect to EMPLOYEE_ID in employee table?

ALTER TABLE INCENTIVES
ADD CONSTRAINT INCENTIVES_FK FOREIGN KEY (EMPLOYEE_REF_ID)
REFERENCES EMPLOYEE(EMPLOYEE_ID);

89. Write SQL to drop foreign key on employee table?

ALTER TABLE INCENTIVES drop CONSTRAINT INCENTIVES_FK;

90. Write SQL to create Orcale Sequence?

CREATE SEQUENCE EMPLOYEE_ID_SEQ START WITH 0 NOMAXVALUE
MINVALUE 0 NOCYCLE NOCACHE NOORDER;

Pages: 1 2 3 4 5 6 7 8 9 10

Translate »