Friday, October 03, 2008
Thursday, October 02, 2008
Cognos 8BI information Sites
http://www.cognoise.com
http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/cognos-8-bi-installation-1437733?cv=expanded#
http://books.google.co.in/books?id=A55Ng8EMGVQC&pg=PA6&lpg=PA6&dq=cognos+8bi++installation+steps&source=web&ots=Ox36-MKXEL&sig=j74I7_3EGeTXHWM10BWHpGWtOjo&hl=en&sa=X&oi=book_result&resnum=5&ct=result#PPA16,M1
http://cognosforums.com/forums/viewforum.php?f=8
http://www.prometricexam.com/BI0-132.htm
http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/cognos-8-bi-installation-1437733?cv=expanded#
http://books.google.co.in/books?id=A55Ng8EMGVQC&pg=PA6&lpg=PA6&dq=cognos+8bi++installation+steps&source=web&ots=Ox36-MKXEL&sig=j74I7_3EGeTXHWM10BWHpGWtOjo&hl=en&sa=X&oi=book_result&resnum=5&ct=result#PPA16,M1
http://cognosforums.com/forums/viewforum.php?f=8
http://www.prometricexam.com/BI0-132.htm
Cognos Installation steps
COGNOS CONFIGURATION
* BEFORE CONFIGURATION:
1. FIRST INSTALL THE SQL SERVER IN THE MIXED MODE (NOT IN WINDOWDS AUTHENTICATION MODE) WITH THE PASWWORD SA.
2. SECOND INSTALL THE COGNOS REPORTNET SOFTWARE CRN AND FWM ONE AFTER OTHER.
NOTE: THE OPRATING SYSTEM SHOULD CONTAIN IIS (INTERNET INFORMATION SERVICE) INSTALLED BEFORE ALL…!
* REPORTNET CONFIGURATION:
1. START->PROGRAM FILES->SQL SERVER->ENTERPRISE MANAGER.
2. ON LEFT HAND SIDE PANEL SELECT MICROSOFT SQL SERVER (EXPAND)-> SERVERGROUP (EXPAND)->WINDOWS NT SERVER (EXPAND).
3. SELECT DATABASES RIGHT CLICK ON IT->NEW DATABASE->NAME IT AS ‘CRN’-> COLLATION NAME AS ‘LATIN1-GENERAL-CI-AS’->CLICK OK->CRN DATABASE IS CREATED.
4. CREATE 2 MORE DATABASES WITH NAME GOSL AND GORT (TO CREATE GOSL, GORT FOLLOW THE ABOVE STEPS WHAT WE HAVE DONE FOR ‘CRN’)->3 NEW DATABASES ARE CREATED.
5. SELECT ‘GORT’ DATABASE RIGHT CLICK ON IT->SELECT ‘ALL TASKS’->CLICK ‘RESTORE DATABASE OPTION’->ONE DIALOG BOX WILL OPENS.
6. SELECT THE BUTTON ‘FROM THE DEVICES’->CLICK ‘SELECT DEVICES’->CLICK ‘ADD’ BUTTON->SELECT THE ‘BROWSE’ BUTTON.
7. PROVIDE THE PATH (C:\PROGAMFILES\COGNOS\CRN\WEBCONTENT\SAMPLES\DATABASE\SQL SERVER\GORT)->CLICK OK-> CLICK OK-> CLICK OK.
8. SELECT THE OPTIONS TAB-> SELECT THE CHECK BOX ‘FORCE RESTORE OVER THE EXISTING DATABASE’->UNDER PHYSICAL DATA FILES WE HAVE TO PROVIDE THE FOLLOWING PATHS INSTEAD OF EXISTING PATHS:
1. C:\PROGRAM FILES\MICROSOFT SQL SERVER\MS SQL\DATA\GORT.mdf
2. C:\PROGRAMFILES\MICROSOFT SQL SERVER\MS SQL\DATA\GORT_log.ldf
9. FOLLOW THE SAME STEPS FOR GOSL DATABASE ASLO (WHAT WE HAVE DONE FOR GORT)
* CONFIGURATION OF REPORT NET SERVER:
1. START->PROGRAM FILES COGNOS REPORTNET-> CLICK ON COGNOS CONFIGURATION.
2. IN THE EXPLORER WINDOW->CLICK ON CONTENT STORE->CORRESPONDING DATABASE PROPERTIES WILL DISPLAYS->PROVIDE DATABASE NAME AS ‘CRN’.
3. CLICK ON USER ID AND PASSWORK->ENTER ‘SA’ FOR USER ID AND PASSWORK->CLICK OK.
4. IN EXPLORER WINDOW CLICK ON COGNOS REPORT NET->HERE SET’DISPATCHED MAXIMUM MEMORY FROM 128 TO 384’-> AFTER THIS SAVE CHANCES MADE-> CLICK ON SAVE BUTTON ON TOOL BAR->CLOSE.
5. IN THIS EXPLORER ONLY WE HAVE TO START REPORT NET SERVER SERVICE FOR THAT-> WE WILL FINE ONE GREEN ARROW BUTTON PRESS THAT BUTTON-> AFTER PRESSING THAT BUTTON IT WILL AUTOMATICALLY CONFIGURES THE SERVER->AFTER COMPLETION OF THAT CLOSE THE EXPLORER.
* CREATION OF VIRTUAL DIRECTORIES:
1. START-> SETTINGS-> CONTROLPANEL->ADMINISTRATIVE TOOLS->INTERNET SERVICE MANAGER.
2. ON LEFT HAND SIDE THE MACHINE NAME WILL APPEAR-> OPEN IT-> EXPAND THE DEFAULT WEBSITE->RIGHT CLICK ON IT->SELECT NEW-> CLICK ON VIRTUAL DIRECTORY->NEXT->IT ASKS FOR ALIAS NAME-> GIVE IT AS ‘CRN’-> NEXT-> CLICK BROWSE->ENTER THE FOLLOWING PATH: (C:\PROGRAMFILES\COGNOS\CRN\WEBCONTENT)->NEXT->BY DEFAULT TWO CHECK BOXES ARE ACTIVATED->UNCHECK THE RUN SCRIPT DIALOG BOX->NEXT FINISH.
3. SELECT ‘CRN’ AND RIGHT CLICK ON IT->SELECT NEW->CLICK ON VIRTUAL DIRECTORY->NEXT-> ALIAS NAME AS ‘CGI-BIN’-> NEXT->PROVIDE FOLLOWING PATH NOW (C:\PROGRAM FILES\COGNOS\CRN\CGI-BIN)->NEXT-> BY DEFAULT TWO CHECK BOXES ARE ACTIVATED->THIS TIME WE NEED TO SELECT THE CHECK BOX ‘EXECUTE’ ALSO -> NEXT-> FINISH.
4. SELECT ‘CRN’ AND RIGHT CLICK ON IT->SELECT NEW->CLICK ON VIRTUAL DIRECTORY->NEXT-> ALIAS NAME AS ‘HELP’-> NEXT->PROVIDE FOLLOWING PATH NOW (C:\PROGRAM FILES\COGNOS\CRN\WEBCONTENT\DOCUMENTATION) ->NEXT-> BY DEFAULT TWO CHECK BOXES ARE ACTIVATED-> UNCHECK THE ‘RUN SCRIPT’ DIALOG BOX->NEXT-> FINISH.
5. UNDER ‘CRN’-> EXPAND SAMPLES FOLDER->SELECT IMAGES FOLDER->RIGHT CLICK ON IMAGES FOLDER->CLICK ON PROPERTIES->SELECT THE CHECK BOX CALLED ‘DIRECTORY BROWSE’ -> CLICK APPLY->OK.
6. TYPE THE FOLLOWING URL IN THE INTERNER EXPLORER (BROWSER)-> http:\localhost\crn.
7. CLICK ON DIRECTORY LINK -> CLICK ON DATASOURCES LINK-> CREATE NEW DATASOURCE (WE WILL FIND ONE DATABASE ICON AT THE RIGHT SIDE TOP OF THE TOOL BAR IN THE EXPLORER) -> PROVIDE NAME AS GOSALES -> CLICK NEXT.
8. SELECT TYPE AS MICROSOFT SQL SERVER -> PROVIDE SERVERNAME AS ‘LOCAL HOST’ AND DATABASE NAME AS ‘GOSL’->SELECT THE CHECK BOX USERID AND PASSWORD THEN ENTER USER ID AND PASSWORK AS ‘SA’ -> TEST-> CLICK OK-> CLICK OK-> CLOSE-> FINISH.
9. AFTER THIS YOU WILL FIND ONE DIALOG BOX (GOSALES DATASOURCE CREATED SUCESSFULLY) THEN CLICK OK
10. SIMILARLY CREATE DATASOURCE FOR GORT (PROVIDE THE NAME AS GORETAILERS) AND FOLLOW THE SAME STEPS WHAT WE HAVE DONE ABOVE FOR GOSL.
11. GO TO HOME PAGE AND CLOSE.
THE END
* BEFORE CONFIGURATION:
1. FIRST INSTALL THE SQL SERVER IN THE MIXED MODE (NOT IN WINDOWDS AUTHENTICATION MODE) WITH THE PASWWORD SA.
2. SECOND INSTALL THE COGNOS REPORTNET SOFTWARE CRN AND FWM ONE AFTER OTHER.
NOTE: THE OPRATING SYSTEM SHOULD CONTAIN IIS (INTERNET INFORMATION SERVICE) INSTALLED BEFORE ALL…!
* REPORTNET CONFIGURATION:
1. START->PROGRAM FILES->SQL SERVER->ENTERPRISE MANAGER.
2. ON LEFT HAND SIDE PANEL SELECT MICROSOFT SQL SERVER (EXPAND)-> SERVERGROUP (EXPAND)->WINDOWS NT SERVER (EXPAND).
3. SELECT DATABASES RIGHT CLICK ON IT->NEW DATABASE->NAME IT AS ‘CRN’-> COLLATION NAME AS ‘LATIN1-GENERAL-CI-AS’->CLICK OK->CRN DATABASE IS CREATED.
4. CREATE 2 MORE DATABASES WITH NAME GOSL AND GORT (TO CREATE GOSL, GORT FOLLOW THE ABOVE STEPS WHAT WE HAVE DONE FOR ‘CRN’)->3 NEW DATABASES ARE CREATED.
5. SELECT ‘GORT’ DATABASE RIGHT CLICK ON IT->SELECT ‘ALL TASKS’->CLICK ‘RESTORE DATABASE OPTION’->ONE DIALOG BOX WILL OPENS.
6. SELECT THE BUTTON ‘FROM THE DEVICES’->CLICK ‘SELECT DEVICES’->CLICK ‘ADD’ BUTTON->SELECT THE ‘BROWSE’ BUTTON.
7. PROVIDE THE PATH (C:\PROGAMFILES\COGNOS\CRN\WEBCONTENT\SAMPLES\DATABASE\SQL SERVER\GORT)->CLICK OK-> CLICK OK-> CLICK OK.
8. SELECT THE OPTIONS TAB-> SELECT THE CHECK BOX ‘FORCE RESTORE OVER THE EXISTING DATABASE’->UNDER PHYSICAL DATA FILES WE HAVE TO PROVIDE THE FOLLOWING PATHS INSTEAD OF EXISTING PATHS:
1. C:\PROGRAM FILES\MICROSOFT SQL SERVER\MS SQL\DATA\GORT.mdf
2. C:\PROGRAMFILES\MICROSOFT SQL SERVER\MS SQL\DATA\GORT_log.ldf
9. FOLLOW THE SAME STEPS FOR GOSL DATABASE ASLO (WHAT WE HAVE DONE FOR GORT)
* CONFIGURATION OF REPORT NET SERVER:
1. START->PROGRAM FILES COGNOS REPORTNET-> CLICK ON COGNOS CONFIGURATION.
2. IN THE EXPLORER WINDOW->CLICK ON CONTENT STORE->CORRESPONDING DATABASE PROPERTIES WILL DISPLAYS->PROVIDE DATABASE NAME AS ‘CRN’.
3. CLICK ON USER ID AND PASSWORK->ENTER ‘SA’ FOR USER ID AND PASSWORK->CLICK OK.
4. IN EXPLORER WINDOW CLICK ON COGNOS REPORT NET->HERE SET’DISPATCHED MAXIMUM MEMORY FROM 128 TO 384’-> AFTER THIS SAVE CHANCES MADE-> CLICK ON SAVE BUTTON ON TOOL BAR->CLOSE.
5. IN THIS EXPLORER ONLY WE HAVE TO START REPORT NET SERVER SERVICE FOR THAT-> WE WILL FINE ONE GREEN ARROW BUTTON PRESS THAT BUTTON-> AFTER PRESSING THAT BUTTON IT WILL AUTOMATICALLY CONFIGURES THE SERVER->AFTER COMPLETION OF THAT CLOSE THE EXPLORER.
* CREATION OF VIRTUAL DIRECTORIES:
1. START-> SETTINGS-> CONTROLPANEL->ADMINISTRATIVE TOOLS->INTERNET SERVICE MANAGER.
2. ON LEFT HAND SIDE THE MACHINE NAME WILL APPEAR-> OPEN IT-> EXPAND THE DEFAULT WEBSITE->RIGHT CLICK ON IT->SELECT NEW-> CLICK ON VIRTUAL DIRECTORY->NEXT->IT ASKS FOR ALIAS NAME-> GIVE IT AS ‘CRN’-> NEXT-> CLICK BROWSE->ENTER THE FOLLOWING PATH: (C:\PROGRAMFILES\COGNOS\CRN\WEBCONTENT)->NEXT->BY DEFAULT TWO CHECK BOXES ARE ACTIVATED->UNCHECK THE RUN SCRIPT DIALOG BOX->NEXT FINISH.
3. SELECT ‘CRN’ AND RIGHT CLICK ON IT->SELECT NEW->CLICK ON VIRTUAL DIRECTORY->NEXT-> ALIAS NAME AS ‘CGI-BIN’-> NEXT->PROVIDE FOLLOWING PATH NOW (C:\PROGRAM FILES\COGNOS\CRN\CGI-BIN)->NEXT-> BY DEFAULT TWO CHECK BOXES ARE ACTIVATED->THIS TIME WE NEED TO SELECT THE CHECK BOX ‘EXECUTE’ ALSO -> NEXT-> FINISH.
4. SELECT ‘CRN’ AND RIGHT CLICK ON IT->SELECT NEW->CLICK ON VIRTUAL DIRECTORY->NEXT-> ALIAS NAME AS ‘HELP’-> NEXT->PROVIDE FOLLOWING PATH NOW (C:\PROGRAM FILES\COGNOS\CRN\WEBCONTENT\DOCUMENTATION) ->NEXT-> BY DEFAULT TWO CHECK BOXES ARE ACTIVATED-> UNCHECK THE ‘RUN SCRIPT’ DIALOG BOX->NEXT-> FINISH.
5. UNDER ‘CRN’-> EXPAND SAMPLES FOLDER->SELECT IMAGES FOLDER->RIGHT CLICK ON IMAGES FOLDER->CLICK ON PROPERTIES->SELECT THE CHECK BOX CALLED ‘DIRECTORY BROWSE’ -> CLICK APPLY->OK.
6. TYPE THE FOLLOWING URL IN THE INTERNER EXPLORER (BROWSER)-> http:\localhost\crn.
7. CLICK ON DIRECTORY LINK -> CLICK ON DATASOURCES LINK-> CREATE NEW DATASOURCE (WE WILL FIND ONE DATABASE ICON AT THE RIGHT SIDE TOP OF THE TOOL BAR IN THE EXPLORER) -> PROVIDE NAME AS GOSALES -> CLICK NEXT.
8. SELECT TYPE AS MICROSOFT SQL SERVER -> PROVIDE SERVERNAME AS ‘LOCAL HOST’ AND DATABASE NAME AS ‘GOSL’->SELECT THE CHECK BOX USERID AND PASSWORD THEN ENTER USER ID AND PASSWORK AS ‘SA’ -> TEST-> CLICK OK-> CLICK OK-> CLOSE-> FINISH.
9. AFTER THIS YOU WILL FIND ONE DIALOG BOX (GOSALES DATASOURCE CREATED SUCESSFULLY) THEN CLICK OK
10. SIMILARLY CREATE DATASOURCE FOR GORT (PROVIDE THE NAME AS GORETAILERS) AND FOLLOW THE SAME STEPS WHAT WE HAVE DONE ABOVE FOR GOSL.
11. GO TO HOME PAGE AND CLOSE.
THE END
Wednesday, October 01, 2008
SQL QUERIES
TABLE SALESPEOPLE
SNUM SNAME CITY COMM
1001 Peel London .12
1002 Serres San Jose .13
1004 Motika London .11
1007 Rafkin Barcelona .15
1003 Axelrod New york .1
TABLE CUST
CNUM CNAME CITY RATING SNUM
2001 Hoffman London 100 1001
2002 Giovanne Rome 200 1003
2003 Liu San Jose 300 1002
2004 Grass Brelin 100 1002
2006 Clemens London 300 1007
2007 Pereira Rome 100 1004
ORDERS
ONUM AMT ODATE CNUM SNUM
3001 18.69 03-OCT-94 2008 1007
3003 767.19 03-OCT-94 2001 1001
3002 1900.10 03-OCT-94 2007 1004
3005 5160.45 03-OCT-94 2003 1002
3006 1098.16 04-OCT-94 2008 1007
3009 1713.23 04-OCT-94 2002 1003
3007 75.75 05-OCT-94 2004 1002
3008 4723.00 05-OCT-94 2006 1001
3010 1309.95 06-OCT-94 2004 1002
3011 9891.88 06-OCT-94 2006 1001
Problems :
1. Display snum,sname,city and comm of all salespeople.
Select snum, sname, city, comm
from salespeople;
2. Display all snum without duplicates from all orders.
Select distinct snum
from orders;
3. Display names and commissions of all salespeople in london.
Select sname,comm
from salespeople
where city = ‘London’;
4. All customers with rating of 100.
Select cname
from cust
where rating = 100;
5. Produce orderno, amount and date form all rows in the order table.
Select ordno, amt, odate
from orders;
6. All customers in San Jose, who have rating more than 200.
Select cname
from cust
where rating > 200;
7. 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;
8. All orders for more than $1000.
Select *
from orders
where amt > 1000;
9. 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’;
10. All customers excluding those with rating <= 100 unless they are located in Rome.
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.
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 customer’s 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 salesperson’s 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 : (' ||
max(rating) || ')'
from cust
group by city;
29. Display the totals of orders for each day and place the results in descending order.
Select odate, count(onum)
from orders
group by odate
order by count(onum);
30. All combinations of salespeople and customers who shared a city. (ie same city).
Select sname, cname
from salespeople, cust
where salespeople.city = cust.city;
31. Name of all customers matched with the salespeople serving them.
Select cname, sname
from cust, salespeople
where cust.snum = salespeople.snum;
32. List each order number followed by the name of the customer who made the 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 salesperson’s 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
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'));
40. 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.
Select cname, city
from cust
where rating = (select rating
from cust
where cname = 'Hoffman')
and cname != 'Hoffman';
44. Extract all the orders of Motika.
Select Onum
from orders
where snum = ( select snum
from salespeople
where sname = ‘Motika’);
45. 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'));
46. 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');
47. Find average commission of salespeople in london.
Select avg(comm)
from salespeople
where city = ‘London’;
48. 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');
49. Extract commissions of all salespeople servicing customers in London.
Select comm
from salespeople
where snum in (select snum
from cust
where city = ‘London’);
50. 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');
51. Count the customers with rating above San Jose’s average.
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 don’t 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)
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 don’t 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
group by snum
having count(*) > 1);
65. 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
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);
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);
77. Select all customers whose ratings are equal to or greater than ANY of the 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);
79. 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);
80. 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;
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 don’t 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
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);
SNUM SNAME CITY COMM
1001 Peel London .12
1002 Serres San Jose .13
1004 Motika London .11
1007 Rafkin Barcelona .15
1003 Axelrod New york .1
TABLE CUST
CNUM CNAME CITY RATING SNUM
2001 Hoffman London 100 1001
2002 Giovanne Rome 200 1003
2003 Liu San Jose 300 1002
2004 Grass Brelin 100 1002
2006 Clemens London 300 1007
2007 Pereira Rome 100 1004
ORDERS
ONUM AMT ODATE CNUM SNUM
3001 18.69 03-OCT-94 2008 1007
3003 767.19 03-OCT-94 2001 1001
3002 1900.10 03-OCT-94 2007 1004
3005 5160.45 03-OCT-94 2003 1002
3006 1098.16 04-OCT-94 2008 1007
3009 1713.23 04-OCT-94 2002 1003
3007 75.75 05-OCT-94 2004 1002
3008 4723.00 05-OCT-94 2006 1001
3010 1309.95 06-OCT-94 2004 1002
3011 9891.88 06-OCT-94 2006 1001
Problems :
1. Display snum,sname,city and comm of all salespeople.
Select snum, sname, city, comm
from salespeople;
2. Display all snum without duplicates from all orders.
Select distinct snum
from orders;
3. Display names and commissions of all salespeople in london.
Select sname,comm
from salespeople
where city = ‘London’;
4. All customers with rating of 100.
Select cname
from cust
where rating = 100;
5. Produce orderno, amount and date form all rows in the order table.
Select ordno, amt, odate
from orders;
6. All customers in San Jose, who have rating more than 200.
Select cname
from cust
where rating > 200;
7. 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;
8. All orders for more than $1000.
Select *
from orders
where amt > 1000;
9. 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’;
10. All customers excluding those with rating <= 100 unless they are located in Rome.
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.
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 customer’s 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 salesperson’s 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 : (' ||
max(rating) || ')'
from cust
group by city;
29. Display the totals of orders for each day and place the results in descending order.
Select odate, count(onum)
from orders
group by odate
order by count(onum);
30. All combinations of salespeople and customers who shared a city. (ie same city).
Select sname, cname
from salespeople, cust
where salespeople.city = cust.city;
31. Name of all customers matched with the salespeople serving them.
Select cname, sname
from cust, salespeople
where cust.snum = salespeople.snum;
32. List each order number followed by the name of the customer who made the 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 salesperson’s 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
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'));
40. 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.
Select cname, city
from cust
where rating = (select rating
from cust
where cname = 'Hoffman')
and cname != 'Hoffman';
44. Extract all the orders of Motika.
Select Onum
from orders
where snum = ( select snum
from salespeople
where sname = ‘Motika’);
45. 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'));
46. 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');
47. Find average commission of salespeople in london.
Select avg(comm)
from salespeople
where city = ‘London’;
48. 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');
49. Extract commissions of all salespeople servicing customers in London.
Select comm
from salespeople
where snum in (select snum
from cust
where city = ‘London’);
50. 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');
51. Count the customers with rating above San Jose’s average.
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 don’t 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)
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 don’t 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
group by snum
having count(*) > 1);
65. 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
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);
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);
77. Select all customers whose ratings are equal to or greater than ANY of the 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);
79. 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);
80. 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;
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 don’t 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
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);
SQL Material
DATA ARE RAW FACTS
EX : CUSTOMER NAME IN BANK
TOTAL MARKS OBTAINED BY STUDENT
INFORMATION: AN ORGANIZED DATA IS CALLED INFORMATION
EX : CUSTOMER NAME WITH BALANCES.
STUDENT REG NO WITH TOTAL MARKS.
DATA HIERARCHY:
BIT IT MAY BE EITHER 0 OR 1
IT REPRESENTS THE SMALLEST PART OF INFORMATION THAT COMPUTER CAN PROCESS.
BYTE : IT IS GROUP OF 8 BITS IT REPRESENTS A DIGIT, LETTERS OR SPECIAL SYMBOL.
FILED: IT IS A GROUP OF CHARACTERS.
EMPNO ENAME SAL JOB
100 SMITH 800 CLERK
RECORD: IT IS A GROUP OF LOGICALLY RELATED FIELD.
FILE : GROUP OF LOGICALLY RELATED RECORDS OR IT IS A FLOW OF CHARACTERS.
DATABASE: IT IS A GROUP OF LOGICALLY RELATED DATA.
(OR)
IT IS THE COLLECTION OF DATA STORED IN A FILE ON DISC
CLASSIFICATION OF DATA BASE BASED ON SIZE
· NORMAL DATABASE:<10 GB
· LARGE DATABASE : 10 GB TO 100 GB
· VERY LARGE DATABASE : 100 GB TO 1000 GB
· EXTREMELY LARGE DATABASE :> 1000 GB
FILE MANAGEMENT SYSTEM
FILE : IT IS A STREAM OF CHARACTERS
DISADVANTAGES :
1. NOT SUPPORT VARIABLES DECLARATION TO STORE (OR) HOLD DATA.
2. WASTAGE OF MEMORY DUE TO DATA REDUNDANCY.
3. MULTIPLE USERS CANNOT ACCESS THE SINGLE FILE AT A TIME.
4. SEARCHING IS A DIFFICULT TASK.
5. INFORMATION ACCESS IS SLOW.
DATABASE MANAGEMENT SYSTEM (DBMS)
IT IS A SUIT OF SOFTWARE PROGRAM FOR CREATING, MAINTAINING & MANIPULATING THE DATA IN DATABASE. (OR)
IT IS A COLLECTION OF INTER RELATED DATA AND SET OF PROGRAM TO ACCESS THE DATA
IT ALLOWS THE ORGANIZATION TO STORE THE DATA IN ONE LOCATION FLOW, WHICH MULTIPLE USERS CAN ACCESS, THE DATA.
DIFFERENT DATABASE MODELS:
1. HIERARCHICAL MODEL
2. NETWORK MODEL
3. RELATIONAL MODEL
DATA IS ORGANIZED IN THE FORM OF TREE STRUCTURE WITH ONE LIMITATION THAT IS
“EVERY SUB NODE SHOULD HAVE ONLY ONE ROOT NODE
DRAWBACKS:
1. DATA REDUNDANCY
2. WASTAGE OF MEMORY
3.CROSS COMMUNICATION IS NOT POSSIBLE
2. NET WORK MODEL:
DATA IS ORGANIZED IN THE FORM OF ARBITRARY GRAPHS.
THERE IS NO GUARANTEE FOR ACCESS OF DATABASE WHENEVER THE DATABASE SIZE INCREASES.
CROSS COMMUNICATION IS POSSIBLE IN NDBMS.
IT CANNOT PROVIDE PROPER QUERY FACILITY, SO THAT WE HAVE TO BIG PROGRAMS EVEN FOR SMALL OPERATION.
3. RELATIONAL MODEL
IT USES THE COLLECTION OF TABLES TO REPRESENT BOTH THE DATA AND RELATIONSHIP AMONG THE DATA.
FEATURES OF RELATIONAL MODEL:
1. DATA IS STORED IN TABLES.
2. INTERSECTION OF ROWS AND COLUMNS WILL GIVE ONLY ONE VALUE.
3. RELATION AMONG DATA IS ESTABLISHED LOGICALLY.
4. THERE IS NO PHYSICAL LINK AMONG DATA
5. THERE IS NO DATA REDUNDANCY
6. HIGH SECURITY FOR DATA
7. IT SUPPORTS ANY TYPE OF DATA (EX: NUMBERS, NUMERIC, DATA, CHARACTER, DATE IMAGES ETC).
8. IT SUPPORTS NULL VALUES.
9. SUPPORT CODD RULES
10. IT SUPPORTS INTEGRITY CONSTRAINTS
11. MULTIPLE USERS CAN ACCESS DATA FROM ANY LOCATION.
NULL VALUE: IT IS UNKNOWN, UNASSIGNED AND UN COMPARABLE VALUE.
EX: 500 + NULL=NULL
ANY ARITHMETIC EXPRESSION CONTAINING NULL IS EVALUATED TO NULL
NULL IS NOT EQUAL TO ZERO OR NOT EQUAL TO SPACE.
RELATIONAL DATABSE: A DATABASE BASED ON RELATIONAL MODEL IS CALLED RELATIONAL DATABASE.
RELATIONAL DATABASE MANAGEMENT SYSTEM (RDBMS): IT IS A SUIT OF SOFTWARE PROGRAMS FOR CREATING, MARINATING AND MANIPULATING THE DATA IN THE RELATIONAL DATABASE.
DIFFERENT RDBMS PACKAGES:
Ø ORACLE
Ø SQL SERVER
Ø DB2
Ø SYBASE
SQL SERVER:
SQL SERVER 2000 IS AN RDBMS THAT USES TRANSACT-SQL TO SEND REQUESTS BETWEEN A CLIENT
COMPUTER AND A SQL SERVER 2000 COMPUTER. AN RDBMS INCLUDES DATABASES, THE DATABASE
ENGINE, AND THE APPLICATIONS THAT ARE NECESSARY TO MANAGE THE DATA AND THE COMPONENTS OF
THE RDBMS. THE RDBMS ORGANIZES DATA INTO RELATED ROWS AND COLUMNS WITHIN THE DATABASE.
THE RDBMS IS RESPONSIBLE FOR ENFORCING THE DATABASE STRUCTURE, INCLUDING THE FOLLOWING
TASKS:
■ MAINTAINING THE RELATIONSHIPS AMONG DATA IN THE DATABASE
■ ENSURING THAT DATA IS STORED CORRECTLY AND THAT THE RULES DEFINING DATA RELATIONSHIPS
ARE NOT VIOLATED
■ RECOVERING ALL DATA TO A POINT OF KNOWN CONSISTENCY IN CASE OF SYSTEM FAILURES
VERSIONS OF SQL SERVER:
1. IN 1993 MICRO SOFT AND SYBASE RELEASES 4.2 VERSION OF SQL SERVER FOR WINDOWS NT ENVIRONMENT.
2. 1995à MICROSOFT RELEASES SQL SERVER 6.0
3. 1996à MICROSOFT RELEASES SQL SERVER 6.5
4. 2000à MICROSOFT RELEASES SQL SERVER 2000
LATEST VERSION SQL SERVER 2005 NOT YET RELEASED.
FEATURES OF SQL SERVER 2000:
1. INTRODUCING SUPPORT FOR XML
2. USER DEFINED FUNCTION ARE INTRODUCED.
3. OLAP (ONLINE ANALYTICAL PROCESS) SERVICES AVAILABLE IN SQL SERVER 7.0 ARE NOW CALLED AS SQL SERVER 2000 ANALYSIS SERVICES
4. REPOSITORY COMPONENTS AVAILABLE IN SQL SERVER NOW CALLED META DATA SERVICES.
DATABASE SIZES:
· MS ACCESS à 2 GB
· SQL SERVER – 6.0 à 1 TB
· SQL SERVER – 7.0 à 1,048,516 TB 3
· SQL SERVER – 2000 à 1,048,516 TB 3
DATABASE IN SQL SERVER:
1) SYSTEM DATABASES
2) USERS DEFINED DATABASES
SYSTEM DATABASES: COMPLETE SYSTEM LEVEL INFORMATION SQL SERVER IS STORED IN SYSTEM DATABASES. SQL SERVER USES SYSTEM DATABASES TO OPERATE USER DATABASES.
USER DATABASES: THE DATABASES CREATED BY USER.
NORMALIZATION
ENTITY : A PERSON, PLACE OR EVENT ABOUT WHICH THE INFORMATION IS STORED IS CALLED ENTITY.
EX: EMPLOYEE, DEPARTMENT, STUDENT, CUSTOMER.
ATTRIBUTE: THE CHARACTERISTIC OR PROPERTY THAT DESCRIBES AN ENTITY IS CALLED ATTRIBUTE.
EX : EMPNO, ENAME, JOB ETC ARE ATTRIBUTE OF ENTITY EMPLOYEE
CUSTID, NAME, ADDRESS ARE ATTRIBUTE OF ENTITY CUSTOMER
FUNCTIONAL DEPENDENCY: IN A RELATION R, AN ATTRIBUTE B IS SAID TO BE FUNCTIONALLY DEPENDENT AN ATTRIBUTE A IF THE VALUE IN B IS UNIQUELY IDENTIFY BY THE VALUE IN A.
THE FUNCTION DEPENDENCY OF ‘B’ AN ‘A’ IS REPRESENTED AS FOLLOWS
R: AàB
EX: 1. SSN à NAME, ADDRESS, DATE OF BIRTH
IE A PERSON NAME, ADDRESS, DATE OF BIRTH
FUNCTIONALLY DEPENDENT ON SOCIAL SECURITY NUMBER(SSN)
2. VIN à MAKE, MODEL, COLOR
IE MAKE, MODEL & COLOR OF VEHICLE FUNCTIONALLY
DEPENDS ON VIN (VEHICLE IDENTIFICATION NUMBER)
PARTIAL FUNCTIONAL DEPENDENCY:
PARTIAL FUNCTIONAL DEPENDENCY IS THE FUNCTIONAL DEPENDENCY IN WHICH SOME NON-KEY COLUMNS DEPENDS ON PART OF KEY COLUMN OR PRIMARY COLUMN.
IN THE ABOVE TABLE EMP NAME, SAL DEPENDS ONLY ON EMP NO BUT THE COURSE COMPLETED DAT WILL DEPENDS ON BOTH EMP NO & COURSE TITLE TO IDENTIFY THE ROW UNIQUELY IN A TABLE EMP NO, COURSE TITLE SHOULD BE DECLARED AS PRIMARY KEY COLUMNS. BUT THE NON-KEY ATTRIBUTES NAME, SQL DEPENDS ONLY EMP NO, IE PART OF A KEY COLUMN THIS TYPE OF FUNCTIONAL DEPENDENCY IS CALLED IT PARTIAL FUNCTIONAL DEPENDENCY.
TRANSITIVE DEPENDENCY
FUNCTIONAL DEPENDENCY BETWEEN THE TWO NON-KEY ATTRIBUTES IS CALLED THE TRANSITIVE DEPENDENCY.
Ø IN THE ABOVE TABLE CUSTID IS IDENTIFIED AS KEY COLUMN
Ø BUT REGION DEPENDS ONLY ON SALESMAN, IS CALLED TRANSITIVE DEPENDENCY.
COLUMNS REGION AND SALESMAN IS CALLED TRANSITIVE DEPENDENCY.
NORMALIZATION ; IT IS THE PROCESS OF DECOMPOSING THE RELATIONS (TABLES) IN TO SMALLER AND WELL STRUCTERD RELATIONS TO MINIMIZE THE DATA REDUNDANCY.
(OR)
IT IS THE PROCESS OF DECIDING WHICH ATTRIBUTED HAS TO GROUPED TO AVOID DATA REDUNDANCY.
THERE ARE SOME RULES IN NORMALIZATION EACH RULE IS CALLED NORMAL FORM.
NORMAL FORMS:
1. FIRST NORMAL FORM (1NF)
2. SECOND NORMAL FORM (2NF)
3. THIRD NORMAL FORM (3NF)
FIRST NORMAL FORMS (1NF): MULTI VALUED ATTRIBUTED SHOULD BE REMOVED FROM THE TABLE.
EXPLANATION: IN THE ABOVE TABLE EMP COURSE TITLE, COURSE COMPLETED DATE ARE MULTI VALUED ATTRIBUTES SINCE AT THE INTERSECTIONS OF ROW AND COLUMN THEY WILL GIVE MOVE THAN ON VALUE. TO BRING THE ABOVE TABLE TO INF MULTI VALUED ATTRIBUTED SHOULD BE REMOVED BY FILLING THE EMPTY FIELD WITH SUITABLE DATA AS SHOWN BELOW.
SECOND NORMAL FORM (2NF) : THE RELATION SHOULD BE IN INF AND THE PARTIAL FUNCTIONAL DEPENDENCY SHOULD BE REMOVED.
IN THE ABOVE TABLE EMP NO, COURSE TITLE ARE IDENTIFIED AS KEY COLUMN BUT NON-KEY COL LIKE NAME AND SQL WILL DEPENDS.
TO BRING THE TABLE TO SECOND NORMAL FORM THE NORMAL FUNCTIONAL DEPENDENCY SHOULD BE REMOVED BY DIVIDING THE TABLE INTO TWO TABLES AS SHOWN ABOVE.
THIRD NORMAL FORM (3NF): THE TABLE SHOULD BE IN THE 2NF AND TRANSITIVE DEPENDENCY SHOULD BE REMOVED.
EX: CUSTOMER
· CUSTID IS IDENTIFIED AS KEY-COLUMN BUT REGION DEPENDS ON SALESMAN.
· THE FUNCTIONAL DEPENDENCY BETWEEN NON-KEY ATTRIBUTES SALES MAN & REGION IS CALLED TRANSITIVE DEPENDENCY.
· TO BRING THE TABLE TO THIRD NORMAL FORM, TRANSITIVE DEPENDENCY SHOULD BE REMOVED BY DIVIDING THE TABLE INTO TWO TABLE AS SHOWN BELOW
SYSTEM AND SAMPLE DATABASE IN SQL SERVER:
WHEN SQL SERVER IS INSTALLED IN A SYSTEM SETUP WILL CREATES THE FOLLOWING SYSTEM AND SAMPLE DATABASE.
SYSTEM DATABASES:
1. MASTER
2. MODEL
3. TEMPDB
4. MSDB
SAMPLE DATABASES:
1. PUBS
2. NORTH WIND
1. MASTER DATABASE : IT CONTAINS SYSTEM LEVEL INFORMATION OF SQL SERVER. ALL LOGINS AND DATABASE INFORMATION IS STORED IN MASTER DATABASE.
2. MODEL DATABASE : IT IS A TEMPLATE FOR USER DATABASES. WHEN USES IS CREATED A DATABASE THE COMPLETE INFORMATION WHICH IS THERE IN MODEL DATA WILL BE COPIED INTO THE USER DATABASE.
3. TEMPDB: IT FOR HOLDING TEMPORARY OBJECTS WHICH ARE CREATED WHEN SQL SERVER STARTS.
4. MSDB: SQL SERVER AGENT FOR SCHEDULING JOBS AND ALERTS USES IT.
PUBS & NORTH WIND: SAMPLE DATABASES
SUB LANGUAGES IN T-SQL COMMANDS:
1. DDL (DATA DEFINITION LANGUAGE)
2. DML (DATA MANIPULATION LANGUAGE)
3. DCL (DATA CONTROL LANGUAGE)
Ø DDL : THESE ARE USED TO CREATE, ALTER AND DROP THE DATABASE OBJECTS.
COMMANDS 1.CREATE
2. ALTER
3. DROP
Ø DML : THESE ARE USED TO INSERT, MODIFY AND DELETE THE DATA IN DATABASE OBJECTS.
à THESE COMMANDS ARE ALSO USED TO RETRIEVE THE DATA IN DB OBJECTS
COMMANDS 1.INSERT
2. UPDATE
3. DELETE
4. SELECT
Ø DCL : THESE ARE USED TO GRAND OR REVOKE THE PERMISSIONS ON DATABASE OBJECTS TO
OTHER USERS
COMMANDS 1.GRANT
2. REVOKE
TABLE IS THE PRIMARY STORAGE UNIT FOR DATA IN DB. MAX NO OF COLUMNS ALLOWED FOR A TABLES ARE 1024, MAX AMOUNT OF DATA ALLOWED PER A ROW 8060 BYTES.
DATA TYPE : THE DATA TYPE SPECIFIES THE TYPE OF DATA THAT CAN BE STORED IN A VARIABLE OR COLUMN OF A TABLE.
DATA TYPE IN SQL SERVER ARE CLASSIFIED INTO TWO TYPES:
1. PREDEFINED DATA TYPES.
2. USER DEFINED DATA TYPES.
PRE DEFINED DATA TYPES:
(a) CHAR [(N)]àFIXED LENGTH DATA TYPE USED TO STORE CHARACTER DATA, STATIC MEMORY ALLOCATION
à IT CAN STORE DATA UP TO 8000CHARACTERS.
à DEFAULT SIZE OF N IS 1 BYTE.
EX: 1.@V1 CHAR (5)
2.@V2 CHAR (10)
(b) VARCHAR (N)àVARIABLE LENGTH DATA TYPE. DYNAMIC MEMORY ALLOCATION
à IT CAN STORE DATA UP TO 8000CHARACTERS.
EX: 1. @ A VARCHAR (5)
MEMORY WILL BE ALLOCATED DYNAMICALLY
(c) NCHAR (N)àFIXED LENGTH OF CHARACTER DATA TYPE
à IT CAN STORE DATA UP TO 4000CHARACTERS.
(d) NVARCHAR (N)àVARIABLE LENGTH CHARACTER DATA TYPE
à IT CAN STORE DATA UP TO 4000 CHARACTERS.
NUMERIC DATA TYPE : USED TO STORE THE NUMERIC VALUES
DATATYPE SIZE
BIGINT 8 BYTES
INT 4 BYTES
SMALLINT 2 BYTES
TINYINT 1 BYTES
FLOAT 8 BYTES
REAL 4 BYTES
DATE DATA TYPE: USED TO STORE DATE AND TIME VALUES.
1. DATE TIME: à USED TO STORE DATE VALUES FROM 1ST JANUARY -1753 TO 31ST DECEMBER - 9999
à DEFAULT SIZE IS 8 BYTES
EX : IS DOJ DATE TIME.
2. DATE TIME: à USED TO STORE DATE VALUES FROM 1ST JANUARY -1990 TO 6TH JUNE - 1979
à DEFAULT SIZE IS 4 BYTES
SQL SERVER SERVICE MANAGER: BY USING THIS DBA CAN STOP, PAUSE OR START THE SERVER.
ENTERPRISE MANAGER: IT IS THE PRIMARY ADMINISTRATIVE TOOL FOR THE ADMINISTRATIVE TASK.
CREATING LOGINS: IN ENTERPRISE MANAGE.
SECURITYà LOGINS
↓ RIGHT CLICK ON THIS
à CLICK ON NEW LOGIN
à SELECT THE SQL SERVER AUTHENTICATION
NAME OF LOGIC
PASSWORD****
CLICK OK
VERIFYING THE PROPERTIES OF LOGIN: CLICK RIGHT CLICK ON LOGIN AND CLICK ON PROPERTIES
DEMO TABLES:
1. EMP TABLE
2. DEPT TABLE
EMP TABLE
EMPNO ENAME JOB MGR SAL COMM. HIREDATE DPTN
7369 SMITH CLERK 7902 800 NULL ----- 20
--- ---- --- --- --- --- ----- ---
--- ---- --- --- --- --- ---- ---
7934 MILLER CLERK 7506 1300 NULL --- 10
DEPT TABLE:
DEPT NO DNAME LOC
10 ACCOUNTING NEWYORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
DDL COMMANDS
CREATE : IT IS USED TO CREATE DATABASE AND ITS OBJECTS LIKE TABLE, VIEWS ETC
à CREATE TABLE STUDENTS ( RNO INT, NAME VARCHAR (20), ADDRESS VARCHAR(50))
[SHIFT+HOME]—COMMANDS IS SELECT
F5à EXECUTE THE COMMAND
DESCRIBING THE STRUCTURE OF A TABLE:
SYNTAX : SP_HELP
ADD
EX : CUSTOMER NAME IN BANK
TOTAL MARKS OBTAINED BY STUDENT
INFORMATION: AN ORGANIZED DATA IS CALLED INFORMATION
EX : CUSTOMER NAME WITH BALANCES.
STUDENT REG NO WITH TOTAL MARKS.
DATA HIERARCHY:
BIT IT MAY BE EITHER 0 OR 1
IT REPRESENTS THE SMALLEST PART OF INFORMATION THAT COMPUTER CAN PROCESS.
BYTE : IT IS GROUP OF 8 BITS IT REPRESENTS A DIGIT, LETTERS OR SPECIAL SYMBOL.
FILED: IT IS A GROUP OF CHARACTERS.
EMPNO ENAME SAL JOB
100 SMITH 800 CLERK
RECORD: IT IS A GROUP OF LOGICALLY RELATED FIELD.
FILE : GROUP OF LOGICALLY RELATED RECORDS OR IT IS A FLOW OF CHARACTERS.
DATABASE: IT IS A GROUP OF LOGICALLY RELATED DATA.
(OR)
IT IS THE COLLECTION OF DATA STORED IN A FILE ON DISC
CLASSIFICATION OF DATA BASE BASED ON SIZE
· NORMAL DATABASE:<10 GB
· LARGE DATABASE : 10 GB TO 100 GB
· VERY LARGE DATABASE : 100 GB TO 1000 GB
· EXTREMELY LARGE DATABASE :> 1000 GB
FILE MANAGEMENT SYSTEM
FILE : IT IS A STREAM OF CHARACTERS
DISADVANTAGES :
1. NOT SUPPORT VARIABLES DECLARATION TO STORE (OR) HOLD DATA.
2. WASTAGE OF MEMORY DUE TO DATA REDUNDANCY.
3. MULTIPLE USERS CANNOT ACCESS THE SINGLE FILE AT A TIME.
4. SEARCHING IS A DIFFICULT TASK.
5. INFORMATION ACCESS IS SLOW.
DATABASE MANAGEMENT SYSTEM (DBMS)
IT IS A SUIT OF SOFTWARE PROGRAM FOR CREATING, MAINTAINING & MANIPULATING THE DATA IN DATABASE. (OR)
IT IS A COLLECTION OF INTER RELATED DATA AND SET OF PROGRAM TO ACCESS THE DATA
IT ALLOWS THE ORGANIZATION TO STORE THE DATA IN ONE LOCATION FLOW, WHICH MULTIPLE USERS CAN ACCESS, THE DATA.
DIFFERENT DATABASE MODELS:
1. HIERARCHICAL MODEL
2. NETWORK MODEL
3. RELATIONAL MODEL
DATA IS ORGANIZED IN THE FORM OF TREE STRUCTURE WITH ONE LIMITATION THAT IS
“EVERY SUB NODE SHOULD HAVE ONLY ONE ROOT NODE
DRAWBACKS:
1. DATA REDUNDANCY
2. WASTAGE OF MEMORY
3.CROSS COMMUNICATION IS NOT POSSIBLE
2. NET WORK MODEL:
DATA IS ORGANIZED IN THE FORM OF ARBITRARY GRAPHS.
THERE IS NO GUARANTEE FOR ACCESS OF DATABASE WHENEVER THE DATABASE SIZE INCREASES.
CROSS COMMUNICATION IS POSSIBLE IN NDBMS.
IT CANNOT PROVIDE PROPER QUERY FACILITY, SO THAT WE HAVE TO BIG PROGRAMS EVEN FOR SMALL OPERATION.
3. RELATIONAL MODEL
IT USES THE COLLECTION OF TABLES TO REPRESENT BOTH THE DATA AND RELATIONSHIP AMONG THE DATA.
FEATURES OF RELATIONAL MODEL:
1. DATA IS STORED IN TABLES.
2. INTERSECTION OF ROWS AND COLUMNS WILL GIVE ONLY ONE VALUE.
3. RELATION AMONG DATA IS ESTABLISHED LOGICALLY.
4. THERE IS NO PHYSICAL LINK AMONG DATA
5. THERE IS NO DATA REDUNDANCY
6. HIGH SECURITY FOR DATA
7. IT SUPPORTS ANY TYPE OF DATA (EX: NUMBERS, NUMERIC, DATA, CHARACTER, DATE IMAGES ETC).
8. IT SUPPORTS NULL VALUES.
9. SUPPORT CODD RULES
10. IT SUPPORTS INTEGRITY CONSTRAINTS
11. MULTIPLE USERS CAN ACCESS DATA FROM ANY LOCATION.
NULL VALUE: IT IS UNKNOWN, UNASSIGNED AND UN COMPARABLE VALUE.
EX: 500 + NULL=NULL
ANY ARITHMETIC EXPRESSION CONTAINING NULL IS EVALUATED TO NULL
NULL IS NOT EQUAL TO ZERO OR NOT EQUAL TO SPACE.
RELATIONAL DATABSE: A DATABASE BASED ON RELATIONAL MODEL IS CALLED RELATIONAL DATABASE.
RELATIONAL DATABASE MANAGEMENT SYSTEM (RDBMS): IT IS A SUIT OF SOFTWARE PROGRAMS FOR CREATING, MARINATING AND MANIPULATING THE DATA IN THE RELATIONAL DATABASE.
DIFFERENT RDBMS PACKAGES:
Ø ORACLE
Ø SQL SERVER
Ø DB2
Ø SYBASE
SQL SERVER:
SQL SERVER 2000 IS AN RDBMS THAT USES TRANSACT-SQL TO SEND REQUESTS BETWEEN A CLIENT
COMPUTER AND A SQL SERVER 2000 COMPUTER. AN RDBMS INCLUDES DATABASES, THE DATABASE
ENGINE, AND THE APPLICATIONS THAT ARE NECESSARY TO MANAGE THE DATA AND THE COMPONENTS OF
THE RDBMS. THE RDBMS ORGANIZES DATA INTO RELATED ROWS AND COLUMNS WITHIN THE DATABASE.
THE RDBMS IS RESPONSIBLE FOR ENFORCING THE DATABASE STRUCTURE, INCLUDING THE FOLLOWING
TASKS:
■ MAINTAINING THE RELATIONSHIPS AMONG DATA IN THE DATABASE
■ ENSURING THAT DATA IS STORED CORRECTLY AND THAT THE RULES DEFINING DATA RELATIONSHIPS
ARE NOT VIOLATED
■ RECOVERING ALL DATA TO A POINT OF KNOWN CONSISTENCY IN CASE OF SYSTEM FAILURES
VERSIONS OF SQL SERVER:
1. IN 1993 MICRO SOFT AND SYBASE RELEASES 4.2 VERSION OF SQL SERVER FOR WINDOWS NT ENVIRONMENT.
2. 1995à MICROSOFT RELEASES SQL SERVER 6.0
3. 1996à MICROSOFT RELEASES SQL SERVER 6.5
4. 2000à MICROSOFT RELEASES SQL SERVER 2000
LATEST VERSION SQL SERVER 2005 NOT YET RELEASED.
FEATURES OF SQL SERVER 2000:
1. INTRODUCING SUPPORT FOR XML
2. USER DEFINED FUNCTION ARE INTRODUCED.
3. OLAP (ONLINE ANALYTICAL PROCESS) SERVICES AVAILABLE IN SQL SERVER 7.0 ARE NOW CALLED AS SQL SERVER 2000 ANALYSIS SERVICES
4. REPOSITORY COMPONENTS AVAILABLE IN SQL SERVER NOW CALLED META DATA SERVICES.
DATABASE SIZES:
· MS ACCESS à 2 GB
· SQL SERVER – 6.0 à 1 TB
· SQL SERVER – 7.0 à 1,048,516 TB 3
· SQL SERVER – 2000 à 1,048,516 TB 3
DATABASE IN SQL SERVER:
1) SYSTEM DATABASES
2) USERS DEFINED DATABASES
SYSTEM DATABASES: COMPLETE SYSTEM LEVEL INFORMATION SQL SERVER IS STORED IN SYSTEM DATABASES. SQL SERVER USES SYSTEM DATABASES TO OPERATE USER DATABASES.
USER DATABASES: THE DATABASES CREATED BY USER.
NORMALIZATION
ENTITY : A PERSON, PLACE OR EVENT ABOUT WHICH THE INFORMATION IS STORED IS CALLED ENTITY.
EX: EMPLOYEE, DEPARTMENT, STUDENT, CUSTOMER.
ATTRIBUTE: THE CHARACTERISTIC OR PROPERTY THAT DESCRIBES AN ENTITY IS CALLED ATTRIBUTE.
EX : EMPNO, ENAME, JOB ETC ARE ATTRIBUTE OF ENTITY EMPLOYEE
CUSTID, NAME, ADDRESS ARE ATTRIBUTE OF ENTITY CUSTOMER
FUNCTIONAL DEPENDENCY: IN A RELATION R, AN ATTRIBUTE B IS SAID TO BE FUNCTIONALLY DEPENDENT AN ATTRIBUTE A IF THE VALUE IN B IS UNIQUELY IDENTIFY BY THE VALUE IN A.
THE FUNCTION DEPENDENCY OF ‘B’ AN ‘A’ IS REPRESENTED AS FOLLOWS
R: AàB
EX: 1. SSN à NAME, ADDRESS, DATE OF BIRTH
IE A PERSON NAME, ADDRESS, DATE OF BIRTH
FUNCTIONALLY DEPENDENT ON SOCIAL SECURITY NUMBER(SSN)
2. VIN à MAKE, MODEL, COLOR
IE MAKE, MODEL & COLOR OF VEHICLE FUNCTIONALLY
DEPENDS ON VIN (VEHICLE IDENTIFICATION NUMBER)
PARTIAL FUNCTIONAL DEPENDENCY:
PARTIAL FUNCTIONAL DEPENDENCY IS THE FUNCTIONAL DEPENDENCY IN WHICH SOME NON-KEY COLUMNS DEPENDS ON PART OF KEY COLUMN OR PRIMARY COLUMN.
IN THE ABOVE TABLE EMP NAME, SAL DEPENDS ONLY ON EMP NO BUT THE COURSE COMPLETED DAT WILL DEPENDS ON BOTH EMP NO & COURSE TITLE TO IDENTIFY THE ROW UNIQUELY IN A TABLE EMP NO, COURSE TITLE SHOULD BE DECLARED AS PRIMARY KEY COLUMNS. BUT THE NON-KEY ATTRIBUTES NAME, SQL DEPENDS ONLY EMP NO, IE PART OF A KEY COLUMN THIS TYPE OF FUNCTIONAL DEPENDENCY IS CALLED IT PARTIAL FUNCTIONAL DEPENDENCY.
TRANSITIVE DEPENDENCY
FUNCTIONAL DEPENDENCY BETWEEN THE TWO NON-KEY ATTRIBUTES IS CALLED THE TRANSITIVE DEPENDENCY.
Ø IN THE ABOVE TABLE CUSTID IS IDENTIFIED AS KEY COLUMN
Ø BUT REGION DEPENDS ONLY ON SALESMAN, IS CALLED TRANSITIVE DEPENDENCY.
COLUMNS REGION AND SALESMAN IS CALLED TRANSITIVE DEPENDENCY.
NORMALIZATION ; IT IS THE PROCESS OF DECOMPOSING THE RELATIONS (TABLES) IN TO SMALLER AND WELL STRUCTERD RELATIONS TO MINIMIZE THE DATA REDUNDANCY.
(OR)
IT IS THE PROCESS OF DECIDING WHICH ATTRIBUTED HAS TO GROUPED TO AVOID DATA REDUNDANCY.
THERE ARE SOME RULES IN NORMALIZATION EACH RULE IS CALLED NORMAL FORM.
NORMAL FORMS:
1. FIRST NORMAL FORM (1NF)
2. SECOND NORMAL FORM (2NF)
3. THIRD NORMAL FORM (3NF)
FIRST NORMAL FORMS (1NF): MULTI VALUED ATTRIBUTED SHOULD BE REMOVED FROM THE TABLE.
EXPLANATION: IN THE ABOVE TABLE EMP COURSE TITLE, COURSE COMPLETED DATE ARE MULTI VALUED ATTRIBUTES SINCE AT THE INTERSECTIONS OF ROW AND COLUMN THEY WILL GIVE MOVE THAN ON VALUE. TO BRING THE ABOVE TABLE TO INF MULTI VALUED ATTRIBUTED SHOULD BE REMOVED BY FILLING THE EMPTY FIELD WITH SUITABLE DATA AS SHOWN BELOW.
SECOND NORMAL FORM (2NF) : THE RELATION SHOULD BE IN INF AND THE PARTIAL FUNCTIONAL DEPENDENCY SHOULD BE REMOVED.
IN THE ABOVE TABLE EMP NO, COURSE TITLE ARE IDENTIFIED AS KEY COLUMN BUT NON-KEY COL LIKE NAME AND SQL WILL DEPENDS.
TO BRING THE TABLE TO SECOND NORMAL FORM THE NORMAL FUNCTIONAL DEPENDENCY SHOULD BE REMOVED BY DIVIDING THE TABLE INTO TWO TABLES AS SHOWN ABOVE.
THIRD NORMAL FORM (3NF): THE TABLE SHOULD BE IN THE 2NF AND TRANSITIVE DEPENDENCY SHOULD BE REMOVED.
EX: CUSTOMER
· CUSTID IS IDENTIFIED AS KEY-COLUMN BUT REGION DEPENDS ON SALESMAN.
· THE FUNCTIONAL DEPENDENCY BETWEEN NON-KEY ATTRIBUTES SALES MAN & REGION IS CALLED TRANSITIVE DEPENDENCY.
· TO BRING THE TABLE TO THIRD NORMAL FORM, TRANSITIVE DEPENDENCY SHOULD BE REMOVED BY DIVIDING THE TABLE INTO TWO TABLE AS SHOWN BELOW
SYSTEM AND SAMPLE DATABASE IN SQL SERVER:
WHEN SQL SERVER IS INSTALLED IN A SYSTEM SETUP WILL CREATES THE FOLLOWING SYSTEM AND SAMPLE DATABASE.
SYSTEM DATABASES:
1. MASTER
2. MODEL
3. TEMPDB
4. MSDB
SAMPLE DATABASES:
1. PUBS
2. NORTH WIND
1. MASTER DATABASE : IT CONTAINS SYSTEM LEVEL INFORMATION OF SQL SERVER. ALL LOGINS AND DATABASE INFORMATION IS STORED IN MASTER DATABASE.
2. MODEL DATABASE : IT IS A TEMPLATE FOR USER DATABASES. WHEN USES IS CREATED A DATABASE THE COMPLETE INFORMATION WHICH IS THERE IN MODEL DATA WILL BE COPIED INTO THE USER DATABASE.
3. TEMPDB: IT FOR HOLDING TEMPORARY OBJECTS WHICH ARE CREATED WHEN SQL SERVER STARTS.
4. MSDB: SQL SERVER AGENT FOR SCHEDULING JOBS AND ALERTS USES IT.
PUBS & NORTH WIND: SAMPLE DATABASES
SUB LANGUAGES IN T-SQL COMMANDS:
1. DDL (DATA DEFINITION LANGUAGE)
2. DML (DATA MANIPULATION LANGUAGE)
3. DCL (DATA CONTROL LANGUAGE)
Ø DDL : THESE ARE USED TO CREATE, ALTER AND DROP THE DATABASE OBJECTS.
COMMANDS 1.CREATE
2. ALTER
3. DROP
Ø DML : THESE ARE USED TO INSERT, MODIFY AND DELETE THE DATA IN DATABASE OBJECTS.
à THESE COMMANDS ARE ALSO USED TO RETRIEVE THE DATA IN DB OBJECTS
COMMANDS 1.INSERT
2. UPDATE
3. DELETE
4. SELECT
Ø DCL : THESE ARE USED TO GRAND OR REVOKE THE PERMISSIONS ON DATABASE OBJECTS TO
OTHER USERS
COMMANDS 1.GRANT
2. REVOKE
TABLE IS THE PRIMARY STORAGE UNIT FOR DATA IN DB. MAX NO OF COLUMNS ALLOWED FOR A TABLES ARE 1024, MAX AMOUNT OF DATA ALLOWED PER A ROW 8060 BYTES.
DATA TYPE : THE DATA TYPE SPECIFIES THE TYPE OF DATA THAT CAN BE STORED IN A VARIABLE OR COLUMN OF A TABLE.
DATA TYPE IN SQL SERVER ARE CLASSIFIED INTO TWO TYPES:
1. PREDEFINED DATA TYPES.
2. USER DEFINED DATA TYPES.
PRE DEFINED DATA TYPES:
(a) CHAR [(N)]àFIXED LENGTH DATA TYPE USED TO STORE CHARACTER DATA, STATIC MEMORY ALLOCATION
à IT CAN STORE DATA UP TO 8000CHARACTERS.
à DEFAULT SIZE OF N IS 1 BYTE.
EX: 1.@V1 CHAR (5)
2.@V2 CHAR (10)
(b) VARCHAR (N)àVARIABLE LENGTH DATA TYPE. DYNAMIC MEMORY ALLOCATION
à IT CAN STORE DATA UP TO 8000CHARACTERS.
EX: 1. @ A VARCHAR (5)
MEMORY WILL BE ALLOCATED DYNAMICALLY
(c) NCHAR (N)àFIXED LENGTH OF CHARACTER DATA TYPE
à IT CAN STORE DATA UP TO 4000CHARACTERS.
(d) NVARCHAR (N)àVARIABLE LENGTH CHARACTER DATA TYPE
à IT CAN STORE DATA UP TO 4000 CHARACTERS.
NUMERIC DATA TYPE : USED TO STORE THE NUMERIC VALUES
DATATYPE SIZE
BIGINT 8 BYTES
INT 4 BYTES
SMALLINT 2 BYTES
TINYINT 1 BYTES
FLOAT 8 BYTES
REAL 4 BYTES
DATE DATA TYPE: USED TO STORE DATE AND TIME VALUES.
1. DATE TIME: à USED TO STORE DATE VALUES FROM 1ST JANUARY -1753 TO 31ST DECEMBER - 9999
à DEFAULT SIZE IS 8 BYTES
EX : IS DOJ DATE TIME.
2. DATE TIME: à USED TO STORE DATE VALUES FROM 1ST JANUARY -1990 TO 6TH JUNE - 1979
à DEFAULT SIZE IS 4 BYTES
SQL SERVER SERVICE MANAGER: BY USING THIS DBA CAN STOP, PAUSE OR START THE SERVER.
ENTERPRISE MANAGER: IT IS THE PRIMARY ADMINISTRATIVE TOOL FOR THE ADMINISTRATIVE TASK.
CREATING LOGINS: IN ENTERPRISE MANAGE.
SECURITYà LOGINS
↓ RIGHT CLICK ON THIS
à CLICK ON NEW LOGIN
à SELECT THE SQL SERVER AUTHENTICATION
NAME OF LOGIC
PASSWORD****
CLICK OK
VERIFYING THE PROPERTIES OF LOGIN: CLICK RIGHT CLICK ON LOGIN AND CLICK ON PROPERTIES
DEMO TABLES:
1. EMP TABLE
2. DEPT TABLE
EMP TABLE
EMPNO ENAME JOB MGR SAL COMM. HIREDATE DPTN
7369 SMITH CLERK 7902 800 NULL ----- 20
--- ---- --- --- --- --- ----- ---
--- ---- --- --- --- --- ---- ---
7934 MILLER CLERK 7506 1300 NULL --- 10
DEPT TABLE:
DEPT NO DNAME LOC
10 ACCOUNTING NEWYORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
DDL COMMANDS
CREATE : IT IS USED TO CREATE DATABASE AND ITS OBJECTS LIKE TABLE, VIEWS ETC
à CREATE TABLE STUDENTS ( RNO INT, NAME VARCHAR (20), ADDRESS VARCHAR(50))
[SHIFT+HOME]—COMMANDS IS SELECT
F5à EXECUTE THE COMMAND
DESCRIBING THE STRUCTURE OF A TABLE:
SYNTAX : SP_HELP