Guest User

Untitled

a guest
Nov 14th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. create table Student
  2. (
  3. regno varchar(20) primary key not null,
  4. name varchar(20),
  5. major varchar(20),
  6. bdate date
  7. );
  8.  
  9. create table Course
  10. (
  11. cno int primary key not null,
  12. cname varchar(20),
  13. dept varchar(20)
  14. );
  15.  
  16. create table Enroll
  17. (
  18. regno varchar(20),
  19. cno int,
  20. sem int,
  21. marks int,
  22. primary key(regno,cno),
  23. foreign key (cno) references Course(cno),
  24. foreign key (regno) references Student(regno)
  25. );
  26.  
  27. create table Text
  28. (
  29. book_isbn int primary key not null,
  30. book_title varchar(20),
  31. publisher varchar(20),
  32. author varchar(20)
  33. );
  34.  
  35. create table Book_Adoption
  36. (
  37. cno int,
  38. sem int,
  39. book_isbn int,
  40. primary key(cno,book_isbn),
  41. foreign key (cno) references Course(cno),
  42. foreign key (book_isbn) references Text(book_isbn)
  43. );
  44. 2: Produce a list of text books (include Course#, Book-ISBN, Book-title) in the alphabetical order for
  45. courses offered by the ̳CS‘ department that use more than two books.
  46.  
  47.  
  48. mysql>select c.cno, t.book_isbn, t.book_title
  49. from course c, book_adoption b, text t
  50. where c.cno=b.cno and t.book_isbn=b.book_isbn and c.dept='cs'
  51. and c.cno in ( select cno
  52. from book_adoption
  53. group by cno
  54. having count(*)>2)
  55. order by c.cno, t.book_title;
  56.  
  57. 3: List any department that has all its adopted books published by a specific publisher.p
  58.  
  59.  
  60. mysql>select distinct c.dept
  61. from course c
  62. where c.dept in
  63. ( select c.dept
  64. from course c,book_adoption b,text t
  65. where c.cno=b.cno
  66. and t.book_isbn=b.book_isbn
  67. and t.publisher='sapna')
  68. and c.dept not in
  69. (select c.dept
  70. from course c,book_adoption b,text t
  71. where c.cno=b.cno
  72. and t.book_isbn=b.book_isbn
  73. and t.publisher!='sapna');
  74. insert into Student values("1jt14cs003","abhinav","cs",'1996-06-11');
  75. insert into Student values("1jt14ae004","abhiram","ae",'1996-05-03');
  76. insert into Student values("1jt14ec046","ajay","cs",'1995-02-26');
  77. insert into Student values("1jt14cvo38","anirudh","civ",'1997-12-22');
  78. insert into Student values("1jt14me056","sharad","me",'1997-10-30');
  79.  
  80.  
  81. insert into Course values(1,"networks","ec");
  82. insert into Course values(2,"simulation","ae");
  83. insert into Course values(3,"survey","civ");
  84. insert into Course values(4,"coding","cs");
  85. insert into Course values(5,"hydraulics","me");
  86. insert into Course values(6,"programing","cs");
  87. insert into Course values(7,"data structures","cs");
  88.  
  89. insert into Enroll values("1jt14ec046",6,1,50);
  90. insert into Enroll values("1jt14ae004",3,3,89);
  91. insert into Enroll values("1jt14cs003",1,3,45);
  92. insert into Enroll values("1jt14cvo38",2,7,73);
  93. insert into Enroll values("1jt14me056",4,5,90);
  94.  
  95. insert into Text values(111,"comp net","tmg","garcia");
  96. insert into Text values(222,"algo des","pearson","levitin");
  97. insert into Text values(333,"automata","pearson","yash");
  98. insert into Text values(444,"data str","sapna","tbaum");
  99. insert into Text values(555,"algo2","pearson","levitin");
  100. insert into Text values(777,"networks","pearson","garcia");
  101.  
  102. insert into Book_Adoption values(1,5,111);
  103. insert into Book_Adoption values(6,3,777);
  104. insert into Book_Adoption values(2,1,555);
  105. insert into Book_Adoption values(4,7,333);
  106. insert into Book_Adoption values(3,5,222);
  107. insert into Book_Adoption values(4,7,111);
  108. insert into Book_Adoption values(6,3,444);
  109. insert into Book_Adoption values(7,5,555);
  110.  
  111.  
  112.  
  113.  
  114.  
  115. <?php
  116. $servername ="localhost";
  117. $username="root";
  118. $password="jit123";
  119. $dbname="db4";
  120.  
  121. $conn= new mysqli($servername,$username,$password,$dbname);
  122.  
  123. if($conn->connection_error)
  124. {
  125. die("CONN failed :" . $conn->connect_error);
  126. }
  127. else
  128. {
  129. $sqlquery="select * from author";
  130. $result = $conn->query($sqlquery);
  131. if($result->num_rows>0)
  132. {echo "<table align=\"center\"border=1> <tr> <th> authorid </th> <th> name</th><th>city</th><th>country</th></tr>";
  133. while($row=$result->fetch_assoc())
  134. {
  135.  
  136. echo "<tr><td>$row[authorid]</td><td>$row[name]</td><td>$row[city]</td><td>$row[country]</td></tr>";
  137.  
  138. }
  139. echo "</table>";
  140. }
  141. else echo "empty set";
  142.  
  143. }
  144.  
  145.  
  146. $conn->close();
  147. ?>
Add Comment
Please, Sign In to add comment