deepak jha

Download deepak jha

Post on 22-Feb-2015

359 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

<p>ASSIGNMENT OF RDBMS(Relational DatabaseManagement System)</p> <p>SUBMITTED TO: Mr. DINESH KUMARSUBMITTED BY: Deepa k REG.N O. 10803590 SECTI ON B6801A20 BATC H: 3</p> <p>ASSIGNMENT 1: TO UNDERSTAND ER DIAGRAM. QUES 1) Draw an ER Diagram for the following scenario: 1) There are multiple banks and each bank has many branches. Each branch has multiple customers 2) Customers have various types of accounts 3) Some Customers also had taken different types of loans from these bank branches 4) One customer can have multiple accounts and Loans ANS: 1) Identify the Entities i) ii) iii) iv) v) Bank Branches Customers Accounts Loans</p> <p>2) Find the Relationships i) Bank has many branches. The Cardinality between Bank and Branch is one to many Bank 1 Has ii) Each branch has multiple customers M Branches</p> <p>The Cardinality between Bank and Branch is one to many Branch 1 Has M Customers</p> <p>iii) One customer can have multiple accounts The Cardinality between Bank and Branch is one to many Customer 1 Has M Accounts</p> <p>iv) One customer can have multiple and Loans The Cardinality between Bank and Branch is one to many Customer 1 Has M Loans</p> <p>3) Identify the Key Attributes Bank Name is the key attribute of Entity Bank which uniquely identifies the Bank Location is the key attribute of Entity Branch which uniquely identifies the Branch Customer# (Customer Id) is the key attribute of Entity Customer which uniquely Identifies the Customer Loan Term is the key attribute of Entity Loan Account Title is the key attribute of Entity Account</p> <p>4) Identify the Other Key Attributes</p> <p>For Bank Entity, the relevant attribute is Location For Branch Entity, the relevant attribute is Name For Customer Entity, the relevant attribute is Name For Loan Entity, the relevant attribute is Loan amount For Account Entity, the relevant attribute is Account type</p> <p>5) Draw the E R Diagram Locatio n</p> <p>Name</p> <p>Location</p> <p>Name</p> <p>1 Bank</p> <p>H as</p> <p>M Branches 1</p> <p>H as</p> <p>M Customers</p> <p>C-Id</p> <p>Name 1 H as Term Amoun t M Loans 1 H as M Accounts Type Title</p> <p>ASSIGNMENT 2: TO CONVERT ER DIAGRAM TO RELATIONAL SCHEMA</p> <p>ANS: The relational schema is: BOOK(ISBN,title,price,year) AUTHOR(name,address) PUBLISHER(emailid,name,telephone#,address) WAREHOUSE (code, phone, and address) AUTHOR E-MAILID TELEPHONE# NAME BOOK ISBN PRICE ADDRESS YEAR</p> <p>PUBLISHER</p> <p>WAREHOUSE</p> <p>CODE</p> <p>PHONE</p> <p>ADDRESS</p> <p>ASSIGNMENT 3: NORMALIZATION QUES 1: Let us find out the Primary Key and highest normal form for this relation: R{a,b,c,d,e,} a,e c, d e, a,eb, a,ed ANS: The Primary Key is ( a,e ) All other attributes are functionally dependent on both a and e. All the attributes are atomic in nature therefore Relation R is in 1NF. All non-key attributes (b, c, d) are fully functionally dependent on the primary key (a, e). Therefore the relation in is 2NF. All the non-key attributes (b, c, d) are non-transitively depending on primary key (a, e). Therefore the relation is in 3NF. QUES 2: Find the primary key and the highest normal form of following relationsa. R{a,b,c} a,bc and ca b. R{a,b,c,d} ab, ad and bc c. R{a,b,c,d,e} a,bc, a,bd and de</p> <p>ANS: a) R {a, b, c} a, bc and ca The Primary Key is (a,b) All the attributes are in atomic level or are atomic in nature therefore Relation R is in 1NF.</p> <p>All non-key attributes are fully functionally dependent on the primary key. Therefore the relation in is 2NF. The relation is also in 3NF b) R {a, b, c, d} ab, ad and bc The Primary Key is a All the attributes are in atomic level or are atomic in nature therefore Relation R is in 1NF. All non-key attributes are fully functionally dependent on the primary key . Therefore the relation in is 2NF. The relation is also in 3NF because all non key attributes are not transitively dependent on key attribute. c) R {a, b, c, d, e} a, bc, a, bd and de The Primary Key is a,b All the attributes are in atomic level or are atomic in nature therefore Relation R is in 1NF. All non-key attributes are fully functionally dependent on the primary key. Therefore the relation in is 2NF. The relation is also in 3NF because all non key attributes are not transitively dependent on key attribute.</p> <p>ASSIGNMENT 4: NORMALIZATION QUES 1: Convert following table to 3NF table. Please add appropriate columns in normalized tables to make 3NF compliant. Note: Consider address column as simple attribute Student Id 1001 1002 1003 1004 1005 Student Name Address Course Id 101 102 103 104 105 Course Name CHSSC PF RDBMS UNIX IWT Date Of Exam 06-Mar-08 15-Mar-08 22-Mar-08 02-Apr-08 10-Apr-08 Marks Grade 83 72 89 63 95 A B A C A</p> <p>21, Lion Blvd, Lawrence St Peter 29, Tiger Blvd, Jagan Burbank 213,Parliament Bobby Blvd, Petas 401,Gazipura Ramsey Blvd,Gulbarga Chang 101,Marshal Hu Blvd,Kingston</p> <p>ANS: All the attributes are in atomic level or are atomic in nature. Therefore the above table is in 1NF For 2NF, we have to remove the partial dependencies. Functional Dependencies of the above table. Let us suppose the table name is Student details Studentdetails (Student Id, Course Id, StudentName, Address, CourseName, Date of Exam, Marks, Grade) Student Id -&gt; StudentName, Address, Marks, Grade {Partially dependent on key attribute}</p> <p>Course Id -&gt; CourseName, Date of Exam {Partially dependent on key attribute} Student Id, Course Id -&gt; Marks, Grade {Fully dependent on key attribute} Marks -&gt; Grade {No dependency on key attribute}</p> <p>After removing the partially dependency, we get the following tables which are in 2NF Student Info Student Id 1001 1002 Jagan 1003 Bobby 1004 Ramsey 1005 Chang Hu Student Name Lawrence Address 21, Lion Blvd, St Peter 29, Tiger Blvd, Burbank 213,Parliament Blvd, Petas 401,Gazipura Blvd,Gulbarga 101,Marshal Blvd,Kingston</p> <p>Course Info Course Id 101 102 103 104 105 Course Name CHSSC PF RDBMS UNIX IWT Date of Exam 06-Mar-08 15-Mar-08 22-Mar-08 02-Apr-08 10-Apr-08</p> <p>Marks Info Student Id 1001 1002 1003 1004 1005 Course Id 101 102 103 104 105 Marks 83 72 89 63 95 Grade A B A C A</p> <p>For 3NF, Non key attributes are not transitively dependent on key attribute. Course Id -&gt; Marks -&gt; Grade The above dependency is a transitive dependency. After removing the transitive dependency, we get the following tables which are in 3NF Marks Info Student Id 1001 1002 1003 1004 1005 Course Id 101 102 103 104 105 Marks 83 72 89 63 95</p> <p>Marks Grade Info Marks 83 72 89 63 Student Id 1001 95 1002 Jagan 1003 Bobby 1004 Ramsey 1005 Chang Hu Grade A B A C Student Name Lawrence A Student Info Address 21, Lion Blvd, St Peter 29, Tiger Blvd, Burbank 213,Parliament Blvd, Petas 401,Gazipura Blvd,Gulbarga 101,Marshal Blvd,Kingston</p> <p>Course Info Course Id 101 102 103 104 105 Course Name CHSSC PF RDBMS UNIX IWT Date of Exam 06-Mar-08 15-Mar-08 22-Mar-08 02-Apr-08 10-Apr-08</p> <p>ASSIGNMENT 5: SQL QUERIES QUES 1: Create the following tables with appropriate constraints and insert the given sample data. i) Applicant Table Column name Data type Description Unique Id generated for an applicant when he or she applies for admission in the college. Name of the applicant email Id of the applicant Complete address of Applicant Constraints</p> <p>ApplicantId ApplicantName EmailId Address City</p> <p>Varchar2(4) Varchar2(30) Varchar2(30) Varchar2(50) Varchar2(15)</p> <p>Primary Key Not null Should be Unique</p> <p>ANS: The query for creation of this table is: CREATE TABLE Applicant (ApplicantId varchar2 (4) CONSTRAINT applicant_pk PRIMARY KEY, ApplicantName varchar2 (30) CONSTRAINT applicant_applicantname_notnull NOT NULL, EmailId varchar2 (30) CONSTRAINT applicant_emailid_uq UNIQUE, Address varchar2 (50), city varchar2 (15));</p> <p>ii) Branch Table Column name BranchId BranchName Data type Varchar2(2) Varchar2(30) Description Unique Id generated for a branch Name of the branch Constraints Primary Key, Should start with B Not Null</p> <p>ANS: The query for creation of this table is: CREATE TABLE Branch (BranchId varchar2 (2) CONSTRAINT branch_pk PRIMARY KEY CONSTRAINT branch_bid CHECK (BranchId like b %), BranchName varchar2 (30) CONSTRAINT branch_branchName_notnull NOTNULL);</p> <p>iii) Course Table Column name CourseId CourseName Semester BranchId Elective ProjectMarks AssignmentMarks InternalMarks Data type Description Varchar2(4) Unique Id given to each course varchar2(30) Name of the course Name of the semester in which the Number(1) course is taught Id of the branch where the course is Varchar2(2) taught char(1) Number(3) Number(3) Number(3) Whether it is elective paper or not Marks of the project in the course (if any) Assignment Marks for the course (if any) Internal Marks for the course (if any) Marks of the semester exam of the course Constraints Primary Key Not Null</p> <p>Foreign key to Branch Table Its value can be 'Y' or 'N' only</p> <p>SemesterExamMarks Number(3)</p> <p>ANS: The query for creation of this table is: CREATE TABLE Course (CourseId varchar2 (4) CONSTRAINT course_pk PRIMARY KEY, CourseName varchar2 (30) CONSTRAINT course_coursename_notnull NOT NULL, Semester number (1),</p> <p>BranchId varchar2 (2) CONSTRAINT course_fk REFERENCES Branch (BranchId), Elective char (1) IN (Y,N), ProjectMarks number (3), AssignmentMarks number (3), Column name StudentId ApplicantId CurrentSemester UserId Password Data type Varchar2(4) Varchar2(4) number(1) Varchar2(15) Varchar2(15) Description Unique id generated for each student when he or she gets admitted in to the college Applicant Id when the student applied for the admission in the college Semester in which the student is currently studying Decided at the time of selection in the college Decided at the time of selection in the college Constraints Primary Key Foreign key to Applicant table It should be unique Not Null</p> <p>InternalMarks number (3), SemesterExamMarks number (3)); iv) Student Table</p> <p>ANS: The query for creation of this table is: CREATE TABLE Student (StudentId varchar2 (4) CONSTRAINT student_pk PRIMARY KEY, ApplicantId varchar2 (4) CONSTRAINT student_fk REFERENCES Applicant (ApplicantId), CurrentSemester number (1), UserId varchar2 (15) CONSTRAINT student_userid_uq UNIQUE, Password varchar2 (15) CONSTRAINT student_password_notnull NOT NULL); v) Registration Table Column name Data type Description Constraints</p> <p>StudentId CourseId DateOfExam ProjectMarks AssignmentMarks InternalMarks SemesterMarks Grade</p> <p>Student Id of the student who has taken Varchar2(4) up the course Course Id of the course in which the Varchar2(4) student has appeared Date on which the semester exam was Date conducted Marks obtained by student in the Number(3) project of the course (if any) Assignment Marks obtained by the Number(3) student for the course (if any) Internal Marks obtained by the student Number(3) for the course (if any) Marks of the semester exam obtained Number(3) by the student for the course Over all grade of the student in the Char(1) course</p> <p>Foreign key to Student table Foreign key to Course table</p> <p>ANS: The query for creation of this table is: CREATE TABLE Registration (StudentId varchar2 (4) CONSTRAINT registration_student_fk REFERENCES Student (StudentId), CourseId varchar2 (4) CONSTRAINT registration_course_fk REFERENCES Course (CourseId), DateOfExam date, ProjectMarks number (3), AssignmentMarks number (3), InternalMarks number (3), SemesterMarks number (3), Grade char (1)); vi) Department Table Column name DepartmentId DepartmentName Data type Description Unique Id generated for Each Number(2) Department Varchar2(30) Name of the Department Constraints Primary Key Not Null</p> <p>Id of Instructor who is managing HeadOfDepartment Varchar2(4) the department ANS: The query for creation of this table is: CREATE TABLE Department</p> <p>(DepartmentId number (2) CONSTRAINT department_pk PRIMARY KEY, Departmentname varchar2 (30) CONSTRAINT department_departmentname-notnull NOT NULL, HeadOfDepartment varchar2 (4));</p> <p>vii) Instructor Table Column name InstructorId InstructorName DateOfJoining Data type Description Constraints Primary Key, Should start with I Not Null Foreign key to Department table</p> <p>Varchar2(4) Unique Id generated for Instructors Varchar2(30) Name of the instructor Date when instructor joins the Date department</p> <p>Department id of the department DepartmentId Number(2) where Instructor works ANS: The query for creation of this table is: CREATE TABLE Instructor</p> <p>(InstructorId varchar2 (4) CONSTRAINT instructor_pk PRIMARY KEY CONSTRAINT instructor_iid CHECK (InstructorId like I %), InstructorName varchar2 (30) CONSTRAINT instructor_instructorname_notnull NOT NULL, DateOfJoining date, DepartmentId number (2) CONSTRAINT instructor_fk REFERENCES Department (DepartmentId)); viii) Course Allocation Table Column name AllocationId CourseId InstructorId Data type Description Unique Id generated whenever ever Number(4) a course is allocated to a instructor Course id of the course for which Varchar2(4) allocation is done Instructor Id of the instructor who Varchar2(4) has been allocated the course Start date when a course is taken up by the instructor( A course can be allocated to the instructor in the Date middle of the semester also) Date till which the course is allocated to the instructor( the instructor can be de allocated from the course in the middle of the Date semester) Constraints Primary key Foreign key to Course table Foreign key to Instructor table</p> <p>StartDate</p> <p>EndDate</p> <p>Can't be less than Start Date</p> <p>ANS: The query for creation of this table is: CREATE TABLE CourseAllocation (AllocationId number (4) CONSTRAINT allocation_pk PRIMARY KEY, CourseId varchar2 (4) CONSTRAINT coursealloction_course_fk REFERENCES Course (CourseId), InstructorId varchar2 (4) CONSTRAINT courseallocation_instructor_fk REFERENCES Instructor (InstructorId), StartDate date, EndDate date CONSTRAINT coursealloction_enddate CHECK (NOT EndDate0), CONSTRAINT hotel_pk PRIMARY KEY (HostelId, Roomno)); x) Attendance Table Colum name Description Student id of the student whos StudentId Varchar2(4) attendance is recorded Course Id of the course in which CourseId Varchar2(4) attendance is recorded TotalLecturedays Number(3) Total no of attendance in the course No of classes the student has attended NoOfDaysPresent Number(3) in the course Datatype Constraints Foreign key to Student table Foreign key to Course table Greater than 0</p> <p>ANS: The query for creation of this table is: CREATE TABLE Attendance (StudentId varchar2 (4) CONSTRAINT attendance_student_fk REFERENCES Student (StudentId), CourseId varchar2 (4) CONSTRAINT attendance_course_fk REFERENCES Course (CourseId), TotalLecturedays number (3) CONSTRAINT totallecture_days CHECK (TotalLecturedays&gt;0), NoOfDaysPresent number (3));</p> <p>a) Applicant Data ApplicantId A001 Vadi A002 Sam A003 A004 A005 A006 A007 A008 A009 A010 A011 Suraj Lakshmi Sandra Vivek Vikas Bipin Gopi Sandy gopi@abc.c om sandy@abc. com sandra@abc. com Vivek_kuma r@abc.com vikas@abc.c om Sam_Sundar @abc.com suraj@abc.c om Applicant Name Raj EmailId raj@abc.co m vadi@abc.c om Address 2nd Street,Hebbal 4th Street,Vijayan gar 5th Street,Edappal li 1st Ma...</p>