Sei sulla pagina 1di 3

Q: What is a Database?

A:

Q: What is the relationship between primary and foreign keys?


A:

Q: Query the employee names and their salaries from the employee table.
A: select ename,sal from emp;

Q: Do the above query and use an �as� clause for the �salary� column aliases or
column headings.
A: select ename,sal as salary from emp;

Q: Repeat the previous query and have �Full Name� for the ename�s column heading
and �Salary� for the �sal� column heading.
A: select ename as "Full Name",sal as salary from emp;

Q: Query the employee names with their commissions.


A: select ename,comm from emp;

Q: Write a query to display the employee name,sal,annual salary of employees.


A: select ename,sal,12*sal "Annual Salary" from emp;

Q: Concatenate the customers� last name and first name separated by comma.
A: select lastname||','||firstname from customer;

Q: Query the employee's names sorted by descending order.


A: select ename from emp order by ename desc;

Q: Query the employee information whose employee number is 7788.


A: select * from emp where empno=7788;

Q: Query the employees name whose names start with the letter �M.�:
A: select ename from emp where ename like 'M.%';

Q: Query the employees name whose names end with the letter �R.�
A: select ename from emp where ename like '%R.';

Q: Query the employees name whose salaries between 2000 and 3000 dollars.
A: select ename,sal from emp where sal between 2000 and 3000;

Q: Query the department number and their total, average, min, and max salaries
for each department.
A: select deptno,sum(sal),avg(sal),max(sal),min(sal) from emp group by deptno;
Q: Query the department no and their total salaries that have more than 5
employees working in their department.
A: select deptno,sum(sal) from emp group by deptno having count(empno)>5;

Q: Query the employees name that work for the Research or Sales department (the
department number 20 or 30).
A: select ename from emp where deptno in(select deptno from dept where dname
in('RESEARCH','SALES'));

Q: Query the employees name that work in the "accounting" department. Assuming
the department number is unknown.
A: select ename from emp where deptno=(select deptno from dept where dname
='ACCOUNTING');

Q: Query the employees name and use the runtime variable to substitute the
department number? Then run it for following department no 10, 20, and 30.
A:

Q: Create an employee table that contains five columns:

Such as Employee Id, last name, First name, Phone number and Department number with
the following constraints.

1. The last name and first name should be not null.

2. Make a check constraint to check the department number is between 9 and 100.

3. Make a primary constraint on the employee ID column.

4. Make a foreign key on the department number column.

5. Use the "delete cascade" to delete all records if parent gets deleted.

6. Use the "phone number" as a unique key.

Q: Query the tables that you as a user own.

Q: Change the size of ename colummn in "emp" table to 30 characters


A: Alter table emp modify(ename varchar2(30));

Q: Insert a record into the "emp" table using column names.


A: insert into emp
values(&empno,'&ename','&job',&mgr,'&hiredate',&sal,&comm,&deptno);
Q: Insert a record into "emp" table using the column position format.
A: insert into emp values( 435,' Raghu',' Analyst',434,'05-MAY-08',3000,300,60);

Q: How do you save the inserted transaction?


A: Commit;

Q: Change the "last_name" column value from �Smith� to �Judd� where the "employee
id" is 100.
A:

Q: Delete all the employee records from the "employee" table using the delete
command and the truncate command.

Q: How do you undo a transaction?


A: Rollback;

Q: What is the difference between the delete statement and the truncate
statement?
A:

Q: Copy the �EMP� table to another table and name the new table "employee." In
the new employee table use the employee name, job, commission and department
number.
A:

Q: Add a salary column to the employee table.


A: Alter table emp add(salary number(10));

Q: Rename the "employee" table to the "iself_employee" table.


A: Rename emp TO iself_employee;

Potrebbero piacerti anche