Sunteți pe pagina 1din 19

NARESH i Technologies

Page no.

1 of 15

TABLE SALESPEOPLE SNUM 1001 1002 1004 1003 TABLE CUST CNUM 2001 2002 2003 2004 2006 2007 ORDERS ONUM 3001 3003 3002 3005 3006 3009 3007 3008 3010 3011 AMT ODATE CNUM 18.69 03-OCT-94 2008 767.19 03-OCT-94 2001 1900.10 03-OCT-94 2007 5160.45 03-OCT-94 2003 1098.16 04-OCT-94 2008 1713.23 04-OCT-94 2002 75.75 05-OCT-94 2004 4723.00 05-OCT-94 2006 1309.95 06-OCT-94 2004 9891.88 06-OCT-94 2006 SNUM 1007 1004 1002 1007 1003 1002 1001 1002 1001 CNAME Hoffman Giovanne Liu Grass Clemens Pereira CITY London Rome San Jose Brelin London Rome RATING 100 200 300 100 300 100 SNUM 1001 1003 1002 1002 1007 1004 SNAME Peel Serres Motika Axelrod CITY London San Jose London New york COMM .12 .13 .15 .1

1001

Problems : 1. 2. 3. Display snum,sname,city and comm of all salespeople. Select snum, sname, city, comm from salespeople; Display all snum without duplicates from all orders. Select distinct snum from orders; Display names and commissions of all salespeople in london. Select sname,comm from salespeople where city = London; All customers with rating of 100. Select cname from cust where rating = 100; Produce orderno, amount and date form all rows in the order table. Select ordno, amt, odate from orders; All customers in San Jose, who have rating more than 200. Select cname from cust where rating > 200;

4.

5. 6.

NARESH i Technologies

Page no.

2 of 15

7.

8.

9.

10. Rome.

All customers who were either located in San Jose or had a rating above 200. Select cname from cust where city = San Jose or rating > 200; All orders for more than $1000. Select * from orders where amt > 1000; Names and citires of all salespeople in london with commission above 0.10. Select sname, city from salepeople where comm > 0.10 and city = London; All customers excluding those with rating <= 100 unless they are located in Select cname from cust where rating <= 100 or city = Rome;

11.

All salespeople either in Barcelona or in london. Select sname, city from salespeople where city in (Barcelona,London); 12. All salespeople with commission between 0.10 and 0.12. (Boundary values should be excluded) Select sname, comm from salespeople where comm > 0.10 and comm < 0.12; 13. All customers with NULL values in city column. Select cname from cust where city is null; 14. All orders taken on Oct 3Rd and Oct 4th 1994. Select * from orders where odate in (03-OCT-94,04-OCT-94); 15. All customers serviced by peel or Motika. Select cname from cust, orders where orders.cnum = cust.cnum and orders.snum in ( select snum from salespeople where sname in 'Peel','Motika')); 16. All customers whose names begin with a letter from A to B. Select cname from cust where cname like A% or cname like B%; 17. All orders except those with 0 or NULL value in amt field.

NARESH i Technologies

Page no.

3 of 15

Select onum from orders where amt != 0 or amt is not null; 18. Count the number of salespeople currently listing orders in the order table. Select count(distinct snum) from orders; 19. Largest order taken by each salesperson, datewise. Select odate, snum, max(amt) from orders group by odate, snum order by odate,snum; 20. Largest order taken by each salesperson with order value more than $3000. Select odate, snum, max(amt) from orders where amt > 3000 group by odate, snum order by odate,snum; 21. Which day had the hightest total amount ordered. Select odate, amt, snum, cnum from orders where amt = (select max(amt) from orders) 22. Count all orders for Oct 3rd. Select count(*) from orders where odate = 03-OCT-94; 23. Count the number of different non NULL city values in customers table. Select count(distinct city) from cust; 24. Select each customers smallest order. Select cnum, min(amt) from orders group by cnum; 25. First customer in alphabetical order whose name begins with G. Select min(cname) from cust where cname like G%; 26. Get the output like For dd/mm/yy there are ___ orders. Select 'For ' || to_char(odate,'dd/mm/yy') || ' there are '|| count(*) || ' Orders' from orders group by odate; 27. Assume that each salesperson has a 12% commission. Produce order no., salesperson no., and amount of salespersons commission for that order. Select onum, snum, amt, amt * 0.12 from orders order by snum; 28. Find highest rating in each city. Put the output in this form. For the city (city), the highest rating is : (rating). Select 'For the city (' || city || '), the highest rating is : (' ||

NARESH i Technologies

Page no.

4 of 15

29. order.

max(rating) || ')' from cust group by city; Display the totals of orders for each day and place the results in descending Select odate, count(onum) from orders group by odate order by count(onum); All combinations of salespeople and customers who shared a city. (ie same Select sname, cname from salespeople, cust where salespeople.city = cust.city; Name of all customers matched with the salespeople serving them. Select cname, sname from cust, salespeople where cust.snum = salespeople.snum; List each order number followed by the name of the customer who made the

30. city).

31.

32. order.

Select onum, cname from orders, cust where orders.cnum = cust.cnum; 33. Names of salesperson and customer for each order after the order number. Select onum, sname, cname from orders, cust, salespeople where orders.cnum = cust.cnum and orders.snum = salespeople.snum; 34. Produce all customer serviced by salespeople with a commission above 12%. Select cname, sname, comm from cust, salespeople where comm > 0.12 and cust.snum = salespeople.snum; 35. Calculate the amount of the salespersons commission on each order with a rating above 100. Select sname, amt * comm from orders, cust, salespeople where rating > 100 and salespeople.snum = cust.snum and salespeople.snum = orders.snum and cust.cnum = orders.cnum 36. Find all pairs of customers having the same rating. Select a.cname, b.cname,a.rating from cust a, cust b where a.rating = b.rating and a.cnum != b.cnum 37. Find all pairs of customers having the same rating, each pair coming once only. Select a.cname, b.cname,a.rating from cust a, cust b where a.rating = b.rating and

NARESH i Technologies

Page no.

5 of 15

a.cnum != b.cnum and a.cnum < b.cnum; 38. Policy is to assign three salesperson to each customers. Display all such combinations. Select cname, sname from salespeople, cust where sname in ( select sname from salespeople where rownum <= 3) order by cname; 39. Display all customers located in cities where salesman serres has customer. Select cname from cust where city = ( select city from cust, salespeople where cust.snum = salespeople.snum and sname = 'Serres'); Select cname from cust where city in ( select city from cust, orders where cust.cnum = orders.cnum and orders.snum in ( select snum from salespeople where sname = 'Serres')); Find all pairs of customers served by single salesperson. Select cname from cust where snum in (select snum from cust group by snum having count(snum) > 1); Select distinct a.cname from cust a ,cust b where a.snum = b.snum and a.rowid != b.rowid; 41. Produce all pairs of salespeople which are living in the same city. Exclude combinations of salespeople with themselves as well as duplicates with the order reversed. Select a.sname, b.sname from salespeople a, salespeople b where a.snum > b.snum and a.city = b.city; 42. Produce all pairs of orders by given customer, names that customers and eliminates duplicates. Select c.cname, a.onum, b.onum from orders a, orders b, cust c where a.cnum = b.cnum and a.onum > b.onum and c.cnum = a.cnum; 43. Produce names and cities of all customers with the same rating as Hoffman.

40.

NARESH i Technologies

Page no.

6 of 15

44.

45.

46.

Select cname, city from cust where rating = (select rating from cust where cname = 'Hoffman') and cname != 'Hoffman'; Extract all the orders of Motika. Select Onum from orders where snum = ( select snum from salespeople where sname = Motika); All orders credited to the same salesperson who services Hoffman. Select onum, sname, cname, amt from orders a, salespeople b, cust c where a.snum = b.snum and a.cnum = c.cnum and a.snum = ( select snum from orders where cnum = ( select cnum from cust where cname = 'Hoffman')); All orders that are greater than the average for Oct 4. Select * from orders where amt > ( select avg(amt) from orders where odate = '03-OCT-94'); Find average commission of salespeople in london. Select avg(comm) from salespeople where city = London; Find all orders attributed to salespeople servicing customers in london. Select snum, cnum from orders where cnum in (select cnum from cust where city = 'London'); Extract commissions of all salespeople servicing customers in London. Select comm from salespeople where snum in (select snum from cust where city = London); Find all customers whose cnum is 1000 above the snum of serres. Select cnum, cname from cust where cnum > ( select snum+1000 from salespeople where sname = 'Serres'); Count the customers with rating above San Joses average.

47.

48.

49.

50.

51.

NARESH i Technologies

Page no.

7 of 15

Select cnum, rating from cust where rating > ( select avg(rating) from cust where city = 'San Jose'); 52. Obtain all orders for the customer named Cisnerous. (Assume you dont know his customer no. (cnum)). Select onum, odate from orders where cnum = ( select cnum from cust where cname = Cisnerous); 53. Produce the names and rating of all customers who have above average orders. Select max(b.cname), max(b.rating), a.cnum from orders a, cust b where a.cnum = b.cnum group by a.cnum having count(a.cnum) > ( select avg(count(cnum)) from orders group by cnum); 54. Find total amount in orders for each salesperson for whom this total is greater than the amount of the largest order in the table. Select snum,sum(amt) from orders group by snum having sum(amt) > ( select max(amt) from orders); 55. Find all customers with order on 3rd Oct. Select cname from cust a, orders b where a.cnum = b.cnum and odate = 03-OCT-94; 56. Find names and numbers of all salesperson who have more than one customer. Select sname, snum from salespeople where snum in ( select snum from cust group by snum having count(snum) > 1 ); 57. Check if the correct salesperson was credited with each sale. Select onum, a.cnum, a.snum, b.snum from orders a, cust b where a.cnum = b.cnum and a.snum != b.snum; 58. Find all orders with above average amounts for their customers. select onum, cnum, amt from orders a where amt > ( select avg(amt)

NARESH i Technologies

Page no.

8 of 15

from orders b where a.cnum = b.cnum group by cnum); 59. Find the sums of the amounts from order table grouped by date, eliminating all those dates where the sum was not at least 2000 above the maximum amount. Select odate, sum(amt) from orders a group by odate having sum(amt) > ( select max(amt) from orders b where a.odate = b.odate group by odate); 60. Find names and numbers of all customers with ratings equal to the maximum for their city. Select a.cnum, a.cname from cust a where a.rating = ( select max(rating) from cust b where a.city = b.city); 61. Find all salespeople who have customers in their cities who they dont service. ( Both way using Join and Correlated subquery.) Select distinct cname from cust a, salespeople b where a.city = b.city and a.snum != b.snum; Select cname from cust where cname in ( select cname from cust a, salespeople b where a.city = b.city and a.snum != b.snum ); 62. Extract cnum,cname and city from customer table if and only if one or more of the customers in the table are located in San Jose. Select * from cust where 2 < (select count(*) from cust where city = 'San Jose'); 63. Find salespeople no. who have multiple customers. Select snum from cust group by snum having count(*) > 1; 64. Find salespeople number, name and city who have multiple customers. Select snum, sname, city from salespeople where snum in ( select snum from cust

NARESH i Technologies

Page no.

9 of 15

65.

group by snum having count(*) > 1); Find salespeople who serve only one customer. Select snum from cust group by snum having count(*) = 1;

66.

Extract rows of all salespeople with more than one current order. Select snum, count(snum) from orders group by snum having count(snum) > 1; 67. Find all salespeople who have customers with a rating of 300. (use EXISTS) Select a.snum from salespeople a where exists ( select b.snum from cust b where b.rating = 300 and a.snum = b.snum) 68. Find all salespeople who have customers with a rating of 300. (use Join). Select a.snum from salespeople a, cust b where b.rating = 300 and a.snum = b.snum; 69. Select all salespeople with customers located in their cities who are not assigned to them. (use EXISTS). Select snum, sname from salespeople where exists ( select cnum from cust where salespeople.city = cust.city and salespeople.snum != cust.snum); 70. Extract from customers table every customer assigned the a salesperson who currently has at least one other customer ( besides the customer being selected) with orders in order table. Select a.cnum, max(c.cname) from orders a, cust c where a.cnum = c.cnum group by a.cnum,a.snum having count(*) < ( select count(*) from orders b where a.snum = b.snum) order by a.cnum; 71. Find salespeople with customers located in their cities ( using both ANY and IN). Select sname from salespeople where snum in ( select snum from cust where salespeople.city = cust.city and

NARESH i Technologies

Page no.

10 of 15

salespeople.snum = cust.snum); Select sname from salespeople where snum = any ( select snum from cust where salespeople.city = cust.city and salespeople.snum = cust.snum); 72. Find all salespeople for whom there are customers that follow them in alphabetical order. (Using ANY and EXISTS) Select sname from salespeople where sname < any ( select cname from cust where salespeople.snum = cust.snum); Select sname from salespeople where exists ( select cname from cust where salespeople.snum = cust.snum and salespeople.sname < cust.cname); 73. Select customers who have a greater rating than any customer in rome. Select a.cname from cust a where city = 'Rome' and rating > ( select max(rating) from cust where city != 'Rome'); 74. Select all orders that had amounts that were greater that atleast one of the orders from Oct 6th. Select onum, amt from orders where odate != '06-oct-94' and amt > ( select min(amt) from orders where odate = '06-oct-94'); 75. Find all orders with amounts smaller than any amount for a customer in San Jose. (Both using ANY and without ANY) Select onum, amt from orders where amt < any ( select amt from orders, cust where city = 'San Jose' and orders.cnum = cust.cnum); Select onum, amt from orders where amt < ( select max(amt) from orders, cust where city = 'San Jose' and orders.cnum = cust.cnum);

NARESH i Technologies

Page no.

11 of 15

76. Select those customers whose ratings are higher than every customer in Paris. ( Using both ALL and NOT EXISTS). Select * from cust where rating > any (select rating from cust where city = 'Paris'); Select * from cust a where not exists ( select b.rating from cust b where b.city != 'Paris' and b.rating > a.rating); Select all customers whose ratings are equal to or greater than ANY of the

77. Seeres.

Select cname, sname from cust, salespeople where rating >= any ( select rating from cust where snum = (select snum from salespeople where sname = 'Serres')) and sname != 'Serres' and salespeople.snum(+) = cust.snum; 78. Find all salespeople who have no customers located in their city. ( Both using ANY and ALL) Select sname from salespeople where snum in ( select snum from cust where salespeople.city != cust.city and salespeople.snum = cust.snum); Select sname from salespeople where snum = any ( select snum from cust where salespeople.city != cust.city and salespeople.snum = cust.snum); Find all orders for amounts greater than any for the customers in London. Select onum, amt from orders where amt > any ( select amt from orders, cust where city = London and orders.cnum = cust.cnum); Find all salespeople and customers located in london. Select sname, cname from cust, salespeople where cust.city = 'London' and salespeople.city = 'London' and cust.snum = salespeople.snum;

79.

80.

NARESH i Technologies

Page no.

12 of 15

81. For every salesperson, dates on which highest and lowest orders were brought. Select a.amt, a.odate, b.amt, b.odate from orders a, orders b where (a.amt, b.amt) in (select max(amt), min(amt) from orders group by snum); 82. List all of the salespeople and indicate those who dont have customers in their cities as well as those who do have. Select snum, city, 'Customer Present' from salespeople a where exists ( select snum from cust where a.snum = cust.snum and a.city = cust.city) UNION select snum, city, 'Customer Not Present' from salespeople a where exists ( select snum from cust c where a.snum = c.snum and a.city != c.city and c.snum not in ( select snum from cust where a.snum = cust.snum and a.city = cust.city)); 83. Append strings to the selected fields, indicating weather or not a given salesperson was matched to a customer in his city. Select a.cname, decode(a.city,b.city,'Matched','Not Matched') from cust a, salespeople b where a.snum = b.snum; 84. Create a union of two queries that shows the names, cities and ratings of all customers. Those with a rating of 200 or greater will also have the words High Rating, while the others will have the words Low Rating. Select cname, cities, rating, Higher Rating from cust where rating >= 200 UNION Select cname, cities, rating, Lower Rating from cust where rating < 200; 85. Write command that produces the name and number of each salesperson and each customer with more than one current order. Put the result in alphabetical order. Select 'Customer Number ' || cnum "Code ",count(*) from orders group by cnum having count(*) > 1 UNION select 'Salesperson Number '||snum,count(*) from orders group by snum

NARESH i Technologies

Page no.

13 of 15

having count(*) > 1; 86. Form a union of three queries. Have the first select the snums of all salespeople in San Jose, then second the cnums of all customers in San Jose and the third the onums of all orders on Oct. 3. Retain duplicates between the last two queries, but eliminates and redundancies between either of them and the first. Select 'Customer Number ' || cnum "Code " from cust where city = 'San Jose' UNION select 'Salesperson Number '||snum from salespeople where city = 'San Jose' UNION ALL select 'Order Number '|| onum from Orders where odate = '03-OCT-94'; 87. Produce all the salesperson in London who had at least one customer there. Select snum, sname from salespeople where snum in ( select snum from cust where cust.snum = salespeople.snum and cust.city = 'London') and city = London; 88. Produce all the salesperson in London who did not have customers there. Select snum, sname from salespeople where snum in ( select snum from cust where cust.snum = salespeople.snum and cust.city = 'London') and city = 'London'; 89. We want to see salespeople matched to their customers without excluding those salesperson who were not currently assigned to any customers. (User OUTER join and UNION) Select sname, cname from cust, salespeople where cust.snum(+) = salespeople.snum; Select sname, cname from cust, salespeople where cust.snum = salespeople.snum UNION select distinct sname, 'No Customer' from cust, salespeople where 0 = (select count(*) from cust where cust.snum = salespeople.snum);

Database Questions

NARESH i Technologies

Page no.

14 of 15

Q) DML insert, update, delete DDL create, alter, drop, truncate, rename. DQL select DCL grant, revoke. TCL commit, rollback, savepoint. Q) Normalization Normalization is the process of simplifying the relationship between data elements in a record. (i) 1st normal form: - 1st N.F is achieved when all repeating groups are removed, and P.K should be defined. big table is broken into many small tables, such that each table has a primary key. (ii) 2nd normal form: - Eliminate any non-full dependence of data item on record keys. I.e. The columns in a table which is not completely dependant on the primary key are taken to a separate table. (iii) 3rd normal form: - Eliminate any transitive dependence of data items on P.Ks. i.e. Removes Transitive dependency. Ie If X is the primary key in a table. Y & Z are columns in the same table. Suppose Z depends only on Y and Y depends on X. Then Z does not depend directly on primary key. So remove Z from the table to a look up table. Q) Diff Primary key and a Unique key? What is foreign key? A) Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only. Foreign key constraint prevents any actions that would destroy link between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity. CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints. Q) Diff Delete & Truncate? A) Rollback is possible after DELETE but TRUNCATE remove the table permanently and cant rollback. Truncate will remove the data permanently we cannot rollback the deleted data. Dropping : (Table structure + Data are deleted), Invalidates the dependent objects, Drops the indexes Truncating : (Data alone deleted), Performs an automatic commit, Faster than delete Delete : (Data alone deleted), Doesnt perform automatic commit

NARESH i Technologies

Page no.

15 of 15

Q) Diff Varchar and Varchar2? A) The difference between Varchar and Varchar2 is both are variable length but only 2000 bytes of character of data can be store in varchar where as 4000 bytes of character of data can be store in varchar2. Q) Diff LONG & LONG RAW?

LONG datatype to store variable-length character strings. The LONG datatype is like the VARCHAR2 datatype, except that the maximum length of a LONG value
A) You use the is 32760 bytes.

LONG RAW datatype to store binary data (or) byte strings. LONG RAW data is like LONG data, except that LONG RAW data is not interpreted by PL/SQL. The maximum length of a LONG RAW value is 32760 bytes.
You use the Q) Diff Function & Procedure Function is a self-contained program segment, function will return a value but procedure not. Procedure is sub program will perform some specific actions. Q) How to find out duplicate rows & delete duplicate rows in a table? A) MPID EMPNAME EMPSSN ----- ---------- ----------1 Jack 555-55-5555 2 Mike 555-58-5555 3 Jack 555-55-5555 4 Mike 555-58-5555 SQL> select count (empssn), empssn from employee group by empssn having count (empssn) > 1; COUNT (EMPSSN) EMPSSN ----------------------2 555-55-5555 2 555-58-5555 SQL> delete from employee where (empid, empssn) not in (select min (empid), empssn from employee group by empssn); Q) Select the nth highest rank from the table? A) Select * from tab t1 where 2=(select count (distinct (t2.sal)) from tab t2 where t1.sal<=t2.sal) Q) a) Emp table where fields empName, empId, address b) Salary table where fields EmpId, month, Amount these 2 tables he wants EmpId, empName and salary for month November? A) Select emp.empId, empName, Amount from emp, salary where emp.empId=salary.empId and month=November; Q) Oracle/PLSQL: Synonyms? A) A synonym is an alternative name for objects such as tables, views, sequences, stored procedures, and other database objects

NARESH i Technologies

Page no.

16 of 15

Syntax: Create [or replace] [public] synonym [schema.] synonym_name for [schema.] object_name; or replace -- allows you to recreate the synonym (if it already exists) without having to issue a DROP synonym command. Public -- means that the synonym is a public synonym and is accessible to all users. Schema -- is the appropriate schema. If this phrase is omitted, Oracle assumes that you are referring to your own schema. object_name -- is the name of the object for which you are creating the synonym. It can be one of the following: Table View sequence Stored procedure Function Package materialized view java class schema object user-defined object Synonym

example: Create public synonym suppliers for app. suppliers; Example demonstrates how to create a synonym called suppliers. Now, users of other schemas can reference the table called suppliers without having to prefix the table name with the schema named app. For example: Select * from suppliers; If this synonym already existed and you wanted to redefine it, you could always use the or replace phrase as follows: Create or replace public synonym suppliers for app. suppliers; Dropping a synonym It is also possible to drop a synonym. drop [public] synonym [schema .] Synonym_name [force]; public -- phrase allows you to drop a public synonym. If you have specified public, then you don't specify a schema. Force -- phrase will force Oracle to drop the synonym even if it has dependencies. It is probably not a good idea to use the force phrase as it can cause invalidation of Oracle objects. Example: Drop public synonym suppliers; This drop statement would drop the synonym called suppliers that we defined earlier. Q) What is an alias and how does it differ from a synonym? A) An alias is an alternative to a synonym, designed for a distributed environment to avoid having to use the location qualifier of a table or view. The alias is not dropped when the table is dropped. Q) What are joins? Inner join & outer join?

NARESH i Technologies

Page no.

17 of 15

A) By using joins, you can retrieve data from two or more tables based on logical relationships
between the tables

Inner Join: - returns all rows from both tables where there is a match. Outer Join: - outer join includes rows from tables when there are no matching values in the tables.
LEFT JOIN or LEFT OUTER JOIN The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table. RIGHT JOIN or RIGHT OUTER JOIN. A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table. FULL JOIN or FULL OUTER JOIN. A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables.

Q. Diff join and a Union? A) A join selects columns from 2 or more tables. A union selects rows. when using the UNION command all selected columns need to be of the same data type. The UNION command eliminate duplicate values. Q. Union & Union All? A) The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. It cannot eliminate duplicate values. > SELECT E_Name FROM Employees_Norway UNION ALL SELECT E_Name FROM Employees_USA Q) Is the foreign key is unique in the primary table? A) Not necessary Q) Table mentioned below named employee ID NAME MID 1 CEO Null 2 VP CEO 3 Director VP Asked to write a query to obtain the following output CEO Null VP CEO Director VP A) SQL> Select a.name, b.name from employee a, employee b where a.mid=b.id(+). Q) Explain a scenario when you dont go for normalization? A) If we r sure that there wont be much data redundancy then dont go for normalization. Q) What is Referential integrity?

NARESH i Technologies

Page no.

18 of 15

A) R.I refers to the consistency that must be maintained between primary and foreign keys, i.e. every foreign key value must have a corresponding primary key value. Q) What techniques are used to retrieve data from more than one table in a single SQL statement? A) Joins, unions and nested selects are used to retrieve data. Q) What is a view? Why use it? A) A view is a virtual table made up of data from base tables and other views, but not stored separately. Q) SELECT statement syntax? A) SELECT [ DISTINCT | ALL ] column_expression1, column_expression2, .... [ FROM from_clause ] [ WHERE where_expression ] [ GROUP BY expression1, expression2, .... ] [ HAVING having_expression ] [ ORDER BY order_column_expr1, order_column_expr2, .... ] column_expression ::= expression [ AS ] [ column_alias ] from_clause ::= select_table1, select_table2, ... from_clause ::= select_table1 LEFT [OUTER] JOIN select_table2 ON expr ... from_clause ::= select_table1 RIGHT [OUTER] JOIN select_table2 ON expr ... from_clause ::= select_table1 [INNER] JOIN select_table2 ... select_table ::= table_name [ AS ] [ table_alias ] select_table ::= ( sub_select_statement ) [ AS ] [ table_alias ] order_column_expr ::= expression [ ASC | DESC ] Q) DISTINCT clause? A) The DISTINCT clause allows you to remove duplicates from the result set. > SELECT DISTINCT city FROM supplier; Q) COUNT function? A) The COUNT function returns the number of rows in a query > SELECT COUNT (*) as "No of emps" FROM employees WHERE salary > 25000; Q) Diff HAVING CLAUSE & WHERE CLAUSE? A) Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. Q) Diff GROUP BY & ORDER BY? A) Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement. > SELECT "col_nam1", SUM("col_nam2") FROM "tab_name" GROUP BY "col_nam1" > SELECT "col_nam" FROM "tab_nam" [WHERE "condition"] ORDER BY "col_nam" [ASC, DESC] Q) What keyword does an SQL SELECT statement use for a string search?

NARESH i Technologies

Page no.

19 of 15

A) The LIKE keyword allows for string searches. The % sign is used as a wildcard. Q) What is a NULL value? What are the pros and cons of using NULLS? A) NULL value takes up one byte of storage and indicates that a value is not present as opposed to a space or zero value. A NULL in a column means no entry has been made in that column. A data value for the column is "unknown" or "not available." Q) Index? Types of indexes? A) Locate rows more quickly and efficiently. It is possible to create an index on one (or) more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries. Unique Index : A unique index means that two rows cannot have the same index value. >CREATE UNIQUE INDEX index_name ON table_name (column_name) When the UNIQUE keyword is omitted, duplicate values are allowed. If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name: >CREATE INDEX PersonIndex ON Person (LastName DESC) If you want to index more than one column you can list the column names within the parentheses. >CREATE INDEX PersonIndex ON Person (LastName, FirstName) Q) Diff subqueries & Correlated subqueries? A)subqueries are self-contained. None of them have used a reference from outside the subquery. correlated subquery cannot be evaluated as an independent query, but can reference columns in a table listed in the from list of the outer query. Q) Predicates IN, ANY, ALL, EXISTS? A) Sub query can return a subset of zero to n values. According to the conditions which one wants to express, one can use the predicates IN, ANY, ALL or EXISTS. The comparison operator is the equality and the logical operation between values is OR. Allows to check if at least a value of the list satisfies condition. Allows to check if condition is realized for all the values of the list. If the subquery returns a result, the value returned is True otherwise the value returned is False.

IN ANY ALL EXISTS

Q) What are some sql Aggregates and other Built-in functions? A) AVG, SUM, MIN, MAX, COUNT and DISTINCT.

S-ar putea să vă placă și