Sie sind auf Seite 1von 10

SQL QUESTIONS with ANSWERS

1)I have used one dml operations like insert statement afterwards used DDl command like alter then immediately used rollback command whether those records are rollback A) No, those records are not rollback the DDl commands are Auto commit. 2)what is the difference between following commands 1)create table emp1 as select * from emp 2) create table emp2 as select * from emp where 1=2; A) The first query will return table structure as well as the table information The second query will create only structure of the table it wont take the information 3)while copying the data one table to another what type of constraints are available A) only not null will be applicable remaining constraints are all disable 4) Difference between alter and update Alter command is used to modify the structure of the table. Update command is used to modify the information of table. 5)Difference between drop, truncate and delete Drop: Drop is the ddl command ,whenever we have used drop command the database object will be deleted perminently from database.we cant rollback it again.we cant use in where clause and we cant use in triggers. Delete: Delete is the dml command whenever we have used delete command the information only deleted the structure can be available .we can rollback the session and we can use in where clause and also we can use delete in while writing triggers. According to performance delete is average case when compare to truncate.
Page 1 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

Truncate: Truncate is the ddl command whenever we have used truncate command the information only deleted perminently, the structure can be available.we cant rollback the data and we cant use where clause and we cant use truncate in triggers. According to performance truncate is better than delete 6) how can we find out the no of records of a table without using count of that table We have one system defined table All_tables, that table will have one column NUM_ROWS. This will show the no of rows. Select * from all_tables where table_name=emp; 7) what is the difference between rowid and rownum Rowid is the hexadecimal format.Rowid can be created whenever we have defined table it can be available physically in database. Most of the time rowid can be used to identify the duplicate rows in table. This is the fastest way to access a row in a table. Rownum is the integer data type format. Row num can be created based on result set(select stmt).it can be available logically in database. 8)difference between where and having Where: If we want to get the data based on some condition then we are going to use where clause with out group by clause Having : If we want to implement the condition with the help of having clause we need to use group clause before having clause 9) single row and multiple row functions Single row functions will always work on single record at a time Multiple row functions will always work on more than on record at a time
Page 2 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

10)Difference between in and exist In will provide us the list of values and it will return only integer values Exist will return Boolean if condition is true it will return true else false. According to performance exists is more better than in 11)select * from emp ordr by sal,deptno, in this query will come in order Here salary will come in asc 12)difference between instring and substring Substr and instr both are character functions By using substring we can find out the length of a string. Eg):select substr(abcdefghij,3,4) from dual; By using instring we can find out the position of the string. Eg): select instr(corporate,or,1) from dual; 13)diff between replace and translate Replace and translate both are single row functions By using replace we can replace the charcter by charcter By using translate we can replace the entire string 14) diff between decode and case or how can we implement if else logic in sql Simply we can use the decode and case 1) Decode is a function 1) case is a statement 2) Decode can be used in sql and 2) case can be used in sql pl/sql 3)We cant use the range 3)we can use the range functionality In decode functionality in case 4)Decode cant work with 4)case can work with Expressions expression 15) which date function will return number value Months_between

Page 3 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

16) with out using the reverse function how can we use reverse the string Using substrig 17) 1)select * from emp where rownum=1 2)select * from emp where rownum<4 3)select * from emp where rownum>4 what is the output of this queries why output come rownum=1 and why output is not come in rownum>4 1) 1 row selected 2) 3 rows selected 3) No rows selected Because row num will always work on first record of resultset it wont have the capability to print the middle record of result set. 18)select count(*),count(job),count(distinct job) what is the difference between these three The Ist one will count the all the records (even null) of a table The IInd one will count the specific coloumn it will takes null and duplicates The III one will count the not null values and unique values 19)select empno, ename from emp where deptno=10 Union Select empno,ename,job from emp where deptno=20 Whether these queries will work or not No its wont execute because both result sets are should contain same list of coloumns and same no of datatypes 20) What is the difference between union and union all Union will display the unique values with sorted results Union all will display all combination of records it means duplicates also Union all is better than union because union wont sort the result.
Page 4 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

21) diff between primary key and unique Primary key is nothing but only one coloumn in a table when ever we have created primary key automatically index, unique,notnull will be created. Primary key wont accept the null values. Where as incase of unique, unique constraint will be created .unique key wont accept the null value Every table should contain only one primary key but unique key can be created n no of times for a table 22) in which table constraint will be stored User_constraints 23) what is on-delete cascade When ever we have applied on delete cascade on child table automatically the child record will be deleted when the parent record is deleted 24) what Is the default It is one type of constraint while creating the table we can give the default value that value will be inserted to coloumn when we inserted null value to that coloumn 25)what is the enhancement of group by clause and how can we get matrix format . Rollup is the enhancement of group by clause we can design the matrix report by using rollup and cube 26) In which level not null will be applicable Not null will be applicable only coloumn level its wont applicable table level 27) what is the difference between join and union Join is a condition. By using join we can join the tables Union is a set operator. By using union we can join the result sets(select stmts) it will sort the result set. 28) what is the inner join and outer join By using inner join we can get the matched records By using outer join we can get matched and unmatched records
Page 5 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

29) what is the sub query and correlated sub query Subquery is nothing but query with in a query. inner query wil give the input to the outer query means the outer query is driven by inner query. Sub query is execute only once. Correlated sub query: Correlated sub query is a special type of sub query it will execute row by row. Here the outer query will give the input the inner query. The inner query will execute as many times of outer query. 30) What is the view and how many types of view View is a one database object. It is a logical representation of select statement. It wont contain the data physically. We have 4 types of views 1) simple view 2)complex view 3)inline view 4)materialized view 31) what is the diff between simple view and complex view Simple view: Simple view derives the data based on only one column. It wont contain the joins, group functions and group by clause. It will allow the dml operations Complex view: Complex view derives the data based on more then one column. It will contain the group by clause, joins and group functions. It wont allow the dml operations directly. We can update the complex view by using instead of triggers. 32) diff between view and inline view View: View is a database object means it can be stored in database perminently. Inline view: Inline view is a select statement in the from clause. I t cant be stored in the database. It can be stored in os buffer

Page 6 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

33) Difference between view and materialized view View : View is a logical representation of select statement. We cant update the complex view directly Materialized view : Materialized view is a physical representation of select statement and it will allow the periodical refreshment. we can update the materialized view directly. 34) Advantages of views 1) If we want to access specific rows of a table then we can create the view 2) We can provide the security by using view 3) We can hide the original name of the database object 35) What is the join and how many types of joins Join is a condition, by using join we can get the data from more than one table Rows in one table can be joined with rows in another table according to common values existing in corresponding columns that is usually primary key and foreign key values. Types of joins are 1) Inner join 2) Natural join 3) Cross join 4) outer join 1) Left outer join 2) Right outer join 3) Full outer join 5) Self join Inner join: By using innerjoin we can get only matched records Natural join: Cross join: A join with out having any condition is the cross join. Every in first table will be joined with every row in another table.
Page 7 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

Outer join: Outer join will produce the results which contains matched and unmatched records Left outer join: Left outer join produces the results which contains all the rows from the left table and matched rows from right table Right outer join: Right outer join produces the results which contains all the rows from the right table and matched rows from left table Full outer join: Full outer join produces the results which contain all the rows from the left table and all the rows from the right table Self join: Self join is join in which a table is joined with it self 36)what is SELECT and VIEW ? select query will execute the statement and return the value where as view is an already compiled statement that rests on the server. we know views are stored as select statement in database these are mainly useful to provide security to the data view is a database object but select is not 37) What is the maximum number of triggers, can apply to a single table? We have 12 max triggers yes we can have 12 triggers on a table 38)What Are the Restrictions on External Table Columns? When creating external table columns, you need to watch out some restrictions:
Page 8 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS


"PRIMARY KEY" is not allowed. "NOT NULL" is not allowed. "DEFAULT value" is not allowed. Virtual columns are not supported An external table does not describe any data that is stored in the database An external table is a read-only source. You cannot perform insert operations into an external table, nor can you update records in an external table.

39)In the following query, which expression is evaluated first? SELECT id_number, (quantity 99/ 1.15 45 * 0.20) FROM hell Ans)99/1.15 this expression evaluated first 40)What Is a Dead Lock in Oracle? Whenever we are doing multiple operations on same table on different sessions That time will get deadlock i.e deadlock 41)How To View Existing Locks on the Database? The current existing data locks are maintained in a Dynamic Performance View called V$LOCK and the information stored is: SID TYPE TX LMODE REQUEST CTIME BLOCK not Session ID to identify the session that owns this lock The type of the lock. E.g.: TM (DML enqueue) and (Transaction enqueue) The lock mode in which the session holds the lock The lock mode in which the session requests the lock The time since current lock mode was granted A value (0 or 1), whether the lock is the blocker or

Page 9 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

SQL QUESTIONS with ANSWERS

Example: User: how to lock and unlock a user account in Oracle. SQL> ALTER USER user_name ACCOUNT LOCK; SQL> ALTER USER user_name ACCOUNT UNLOCK; List the empno, ename, sal, dname, loc, deptno, j o b o f a l l e m p s working at CHICAGO or working for ACCOUNTING dept wit ann sal >28000, but the sal should not be = 3000 or 2800 who doesnt belongsto the Mgr and whose no is having a digit 7 or 8 in 3 rd position in theasc order of deptno and desc order of job. SQL>SELECT EMPNO, E N A M E , J O B , S A L , E M P . D E P T N O , d n a m e , l o c FROM EMP, DEPTWHERE (LOC = 'CHICAGO' OR DNAME = 'ACCOUNTING')AND SAL*12 > 28000 AND SAL NOT IN(3000,2800)AND MGR IS NULL AND EMPNO LIKE '__7_' OR EMPNO LIKE'__8_'AND EMP.DEPTNO = DEPT.DEPTNO ORDER BY EMP.DEPTNO ASC, JOB DESC

Page 10 of 10 Prepared by, * Vng Technologies * -- R.VIJAY KUMAR--

Das könnte Ihnen auch gefallen