Tài liệu Practical Database Programming With Visual C#.NET- P2 pdf

50 961 1
Tài liệu Practical Database Programming With Visual C#.NET- P2 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

2.11 Create Oracle 10g XE Sample Database 73 Figure 2.51 Completed LogIn table. length of the string depends on the number of real letters entered by the user. The data types for all columns are VARCHAR2 with one exception, which is the phone column that has a CHAR type with an upper bound of 12 letters since our phone numbers are composed of 10 digits, and we can extend this length to 12 with two dashes. For all other columns, the length varies with the different information, so the VARCHAR2 is selected for those columns. The fi nished design view of your Faculty table is shown in Figure 2.52 . You need to check the Not Null checkbox for the faculty_id column since we selected this column as the primary key for this table. Click on the Next button to go to the next page to add the primary key for this table, which is shown in Figure 2.53 . Check the Not Populated from the primary key list since we don ’ t want to use any Sequence object to automatically generate a sequence of numeric numbers as our primary key, and then select the FACULTY_ID(VARCHAR2) from the Primary Key textbox. In this way, the faculty_id column is selected as the primary key for this table. Keep the Composite Primary Key box untouched since we do not have that kind of key in this table, and click on the Next button to go to the next page. Since we have not created all other tables to work as our reference tables for the foreign key, click on Next to continue, and we will do the foreign key for this table later. Click on the Finish button to go to the Confi rm page. Finally click on the Create button to create this new Faculty table. Your completed columns in the Faculty table are shown in Figure 2.54 . c02.indd 73c02.indd 73 2/11/2010 11:50:06 AM2/11/2010 11:50:06 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 74 Chapter 2 Introduction to Databases Figure 2.52 Finished design view of the Faculty table. Figure 2.53 Opened Primary Key window. c02.indd 74c02.indd 74 2/11/2010 11:50:08 AM2/11/2010 11:50:08 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 2.11 Create Oracle 10g XE Sample Database 75 Figure 2.54 Completed columns in the Faculty table. Table 2.24 Data in the Faculty Table faculty_id faculty_name office phone college title email A52990 Black Anderson MTC-218 750-378-9987 Virginia Tech Professor banderson@college.edu A77587 Debby Angles MTC-320 750-330-2276 University of Chicago Associate Professor dangles@college.edu B66750 Alice Brown MTC-257 750-330-6650 University of Florida Assistant Professor abrown@college.edu B78880 Ying Bai MTC-211 750-378-1148 Florida Atlantic University Associate Professor ybai@college.edu B86590 Satish Bhalla MTC-214 750-378-1061 University of Notre Dame Associate Professor sbhalla@college.edu H99118 Jeff Henry MTC-336 750-330-8650 Ohio State University Associate Professor jhenry@college.edu J33486 Steve Johnson MTC-118 750-330-1116 Harvard University Distinguished Professor sjohnson@college.edu K69880 Jenney King MTC-324 750-378-1230 East Florida University Professor jking@college.edu Now click on the Data object tool to add the data into this new table. Click on the Insert Row button to add all rows that are shown in Table 2.24 into this table. Click on the Create and Create Another button when the fi rst row is done, and con- tinue to create all rows with the data shown in Table 2.24 . You may click on the Create button for your last row. Your fi nished Faculty table should match the one shown in Figure 2.55 . 2.11.2.3 Create Other Tables In a similar way, you can continue to create the following three tables: Course, Student, and StudentCourse based on the data shown in Tables 2.25 , 2.26 , and 2.27 . c02.indd 75c02.indd 75 2/11/2010 11:50:12 AM2/11/2010 11:50:12 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 76 Chapter 2 Introduction to Databases Figure 2.55 Finished Faculty table. The data types used in the Course table are: • course_id: VARCHAR2(10) — primary Key • course: VARCHAR2(40) • credit: NUMBER(1, 0) — precision = 1, scale = 0 (1 - bit integer) • classroom: CHAR(6) • schedule: VARCHAR2(40) • enrollment: NUMBER(2, 0) — precision = 2, scale = 0 (2 - bit integer) • faculty_id: VARCHAR2(10) The data types used in the Student table are: • student_id: VARCHAR2(10) — primary Key • student_name: VARCHAR2(20) • gpa: NUMBER(3, 2) — precision = 3, scale = 2 (3 - bit fl oating point data with 2 - bit after the decimal point) • credits: NUMBER(3, 0) — precision = 3, scale = 0 (3 - bit integer) • major: VARCHAR2(40) • schoolYear: VARCHAR2(20) • email: VARCHAR2(20) The data types used in the StudentCourse table are: • s_course_id: NUMBER(4, 0) — precision = 4, scale = 0 (4 - bit integer) primary key • student_id: VARCHAR2(10) c02.indd 76c02.indd 76 2/11/2010 11:50:14 AM2/11/2010 11:50:14 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 2.11 Create Oracle 10g XE Sample Database 77 Table 2.25 Data in the Course Table course_id course credit classroom schedule enrollment faculty_id CSC-131A Computers in Society 3 TC-109 M-W-F: 9:00-9:55 AM 28 A52990 CSC-131B Computers in Society 3 TC-114 M-W-F: 9:00-9:55 AM 20 B66750 CSC-131C Computers in Society 3 TC-109 T-H: 11:00-12:25 PM 25 A52990 CSC-131D Computers in Society 3 TC-119 M-W-F: 9:00-9:55 AM 30 B86590 CSC-131E Computers in Society 3 TC-301 M-W-F: 1:00-1:55 PM 25 B66750 CSC-131F Computers in Society 3 TC-109 T-H: 1:00-2:25 PM 32 A52990 CSC-132A Introduction to Programming 3 TC-303 M-W-F: 9:00-9:55 AM 21 J33486 CSC-132B Introduction to Programming 3 TC-302 T-H: 1:00-2:25 PM 21 B78880 CSC-230 Algorithms & Structures 3 TC-301 M-W-F: 1:00-1:55 PM 20 A77587 CSC-232A Programming I 3 TC-305 T-H: 11:00-12:25 PM 28 B66750 CSC-232B Programming I 3 TC-303 T-H: 11:00-12:25 PM 17 A77587 CSC-233A Introduction to Algorithms 3 TC-302 M-W-F: 9:00-9:55 AM 18 H99118 CSC-233B Introduction to Algorithms 3 TC-302 M-W-F: 11:00-11:55 AM 19 K69880 CSC-234A Data Structure & Algorithms 3 TC-302 M-W-F: 9:00-9:55 AM 25 B78880 CSC-234B Data Structure & Algorithms 3 TC-114 T-H: 11:00-12:25 PM 15 J33486 CSC-242 Programming II 3 TC-303 T-H: 1:00-2:25 PM 18 A52990 CSC-320 Object Oriented Programming 3 TC-301 T-H: 1:00-2:25 PM 22 B66750 CSC-331 Applications Programming 3 TC-109 T-H: 11:00-12:25 PM 28 H99118 CSC-333A Computer Arch & Algorithms 3 TC-301 M-W-F: 10:00-10:55 AM 22 A77587 CSC-333B Computer Arch & Algorithms 3 TC-302 T-H: 11:00-12:25 PM 15 A77587 CSC-335 Internet Programming 3 TC-303 M-W-F: 1:00-1:55 PM 25 B66750 CSC-432 Discrete Algorithms 3 TC-206 T-H: 11:00-12:25 PM 20 B86590 CSC-439 Database Systems 3 TC-206 M-W-F: 1:00-1:55 PM 18 B86590 CSE-138A Introduction to CSE 3 TC-301 T-H: 1:00-2:25 PM 15 A52990 CSE-138B Introduction to CSE 3 TC-109 T-H: 1:00-2:25 PM 35 J33486 CSE-330 Digital Logic Circuits 3 TC-305 M-W-F: 9:00-9:55 AM 26 K69880 CSE-332 Foundations of Semiconductors 3 TC-305 T-H: 1:00-2:25 PM 24 K69880 CSE-334 Elec Measurement & Design 3 TC-212 T-H: 11:00-12:25 PM 25 H99118 CSE-430 Bioinformatics in Computer 3 TC-206 Thu: 9:30-11:00 AM 16 B86590 CSE-432 Analog Circuits Design 3 TC-309 M-W-F: 2:00-2:55 PM 18 K69880 CSE-433 Digital Signal Processing 3 TC-206 T-H: 2:00-3:25 PM 18 H99118 CSE-434 Advanced Electronics Systems 3 TC-213 M-W-F: 1:00-1:55 PM 26 B78880 CSE-436 Automatic Control and Design 3 TC-305 M-W-F: 10:00-10:55 AM 29 J33486 CSE-437 Operating Systems 3 TC-303 T-H: 1:00-2:25 PM 17 A77587 CSE-438 Advd Logic & Microprocessor 3 TC-213 M-W-F: 11:00-11:55 AM 35 B78880 CSE-439 Special Topics in CSE 3 TC-206 M-W-F: 10:00-10:55 AM 22 J33486 Table 2.26 Data in the Student Table student_id student_name gpa credits major schoolYear email A78835 Andrew Woods 3.26 108 Computer Science Senior awoods@college.edu A97850 Ashly Jade 3.57 116 Information System Engineering Junior ajade@college.edu B92996 Blue Valley 3.52 102 Computer Science Senior bvalley@college.edu H10210 Holes Smith 3.87 78 Computer Engineering Sophomore hsmith@college.edu J77896 Erica Johnson 3.95 127 Computer Science Senior ejohnson@college.edu c02.indd 77c02.indd 77 2/11/2010 11:50:15 AM2/11/2010 11:50:15 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 78 Chapter 2 Introduction to Databases • course_id: VARCHAR2(10) • credit: NUMBER(1, 0) — precision = 1, scale = 0 (1 - bit integer) • major: VARCHAR2(40) Your fi nished Course, Student, and StudentCourse tables are shown in Figures 2.56 , 2.57 and 2.58 , respectively. 2.11.3 Create Constraints Between Tables Now it is the time for us to set up the relationships between our fi ve tables using the primary and foreign keys. Since we have already selected the primary key for each table when we create and build those tables, therefore we only need to take care of the foreign keys and connect them with the associated primary keys in the related tables. Let ’ s start from the fi rst table, LogIn table. Table 2.27 Data in the Student C ourse Table s_course_id student_id course_id credit major 1000 H10210 CSC-131D 3 CE 1001 B92996 CSC-132A 3 CS/IS 1002 J77896 CSC-335 3 CS/IS 1003 A78835 CSC-331 3 CE 1004 H10210 CSC-234B 3 CE 1005 J77896 CSC-234A 3 CS/IS 1006 B92996 CSC-233A 3 CS/IS 1007 A78835 CSC-132A 3 CE 1008 A78835 CSE-432 3 CE 1009 A78835 CSE-434 3 CE 1010 J77896 CSC-439 3 CS/IS 1011 H10210 CSC-132A 3 CE 1012 H10210 CSC-331 3 CE 1013 A78835 CSC-335 3 CE 1014 A78835 CSE-438 3 CE 1015 J77896 CSC-432 3 CS/IS 1016 A97850 CSC-132B 3 ISE 1017 A97850 CSC-234A 3 ISE 1018 A97850 CSC-331 3 ISE 1019 A97850 CSC-335 3 ISE 1020 J77896 CSE-439 3 CS/IS 1021 B92996 CSC-230 3 CS/IS 1022 A78835 CSE-332 3 CE 1023 B92996 CSE-430 3 CE 1024 J77896 CSC-333A 3 CS/IS 1025 H10210 CSE-433 3 CE 1026 H10210 CSE-334 3 CE 1027 B92996 CSC-131C 3 CS/IS 1028 B92996 CSC-439 3 CS/IS c02.indd 78c02.indd 78 2/11/2010 11:50:16 AM2/11/2010 11:50:16 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 2.11 Create Oracle 10g XE Sample Database 79 Figure 2.56 Completed Course table. Figure 2.57 Completed Student table. c02.indd 79c02.indd 79 2/11/2010 11:50:16 AM2/11/2010 11:50:16 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 80 Chapter 2 Introduction to Databases 2.11.3.1 Create Constraints Between Log In and Faculty Tables Now let ’ s create the constraints between the LogIn and the Faculty tables by using a foreign key. Create a foreign key for the LogIn table and connect it to the primary key in the Faculty table. The faculty_id is a foreign key in the LogIn table but it is a primary key in the Faculty table. A one - to - many relationship exists between the faculty_id in the Faculty table and the faculty_id in the LogIn table. Log on the Oracle Database 10g XE using the customer user name, CSE_DEPT, and the customer database password, and then open the home page of the Oracle Database 10g XE. Click on the Object Browser icon and select Browse|Table to list all tables. Select the LogIn table from the left pane to open it, click the Constraints tab and then click the Create button that is the fi rst button in the second row. Enter LOGIN_FACULTY_FK into the Constraint Name box, and select the Foreign Key from the Constraint Type box, which is shown in Figure 2.59 . Check the On Delete Cascade checkbox. Then select the FACULTY_ID from the LogIn table as the foreign key column. Select the FACULTY Figure 2.58 Completed StudentCourse table. c02.indd 80c02.indd 80 2/11/2010 11:50:19 AM2/11/2010 11:50:19 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 2.11 Create Oracle 10g XE Sample Database 81 Figure 2.59 Create the foreign key between the LogIn and the Faculty table. table from the Reference Table Name box as the reference table, and select the FACULTY_ID from the Reference Table Column List as the reference table column. Your fi nished Add Constraint window should match the one shown in Figure 2.59 . Click on Next to go to the next window, and then click on the Finish button to confi rm this foreign key ’ s creation. 2.11.3.2 Create Constraints Between Log In and Student Tables The relationship between the Student table and the LogIn table is a one - to - many rela- tionship. The student_id in the Student table is a primary key, but the student_id in the LogIn table is a foreign key. Multiple student_ids can exists in the LogIn table, but only one or a unique student_id can be found from the Student table. To create a foreign key from the LogIn table and connect it to the primary key in the Student table, open the LogIn table if it is not opened and click on the Constraints tab, and then click on the Create button that is the fi rst button in the second row to open the Add Constraint window. Enter LOGIN_STUDENT_FK into the Constraint Name box, and select the Foreign Key from the Constraint Type box, which is shown in Figure 2.60 . Check the On Delete Cascade checkbox. Then select the STUDENT_ID from the LogIn table as the foreign key column. Select the STUDENT table from the Reference Table Name box as the reference table, and select the STUDENT_ID from the Reference Table Column List as the reference table column. Your fi nished Add Constraint window should match the one shown in Figure 2.60 . c02.indd 81c02.indd 81 2/11/2010 11:50:21 AM2/11/2010 11:50:21 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 82 Chapter 2 Introduction to Databases Figure 2.61 Finished foreign key creation window for the LogIn table. Recall that when we created the LogIn table in Section 2.11.2.1 , we emphasized that for the blank fi elds in both faculty_id and student_id columns, don ’ t place a NULL into these fi elds and just leave those fi elds blank. The reason for this is that an ALTER TABLE command will be issued when you create a foreign key for the LogIn table, and the NULL cannot be recognized by this command, therefore an error ORA - 02298 occurs and your creation of a foreign key will fail. Click on the Next button to go to the next window, and then click on the Finish button to confi rm this foreign key ’ s creation. Your fi nished foreign key creation window for the LogIn table should match the one shown in Figure 2.61 . Figure 2.60 Create the foreign key between the LogIn and the Student table. c02.indd 82c02.indd 82 2/11/2010 11:50:23 AM2/11/2010 11:50:23 AM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... relational database were analyzed in detailed with some real data tables in our sample database CSE_DEPT The process in developing and building a sample database was discussed in detail with the following points: • Defining relationships • Normalizing the data • Implementing the relational database Homework 87 In the second part of this chapter, three sample databases that were developed with three popular database. .. Practical Database Programming With Visual C#.NET, by Ying Bai Copyright © 2010 the Institute of Electrical and Electronics Engineers, Inc 91 92 Chapter 3 Introduction to ADO.NET ferred interface for Visual Basic programmers to access various data sources, with ADO 2.7 being the latest version of this technology The development history of data accessing methods can be traced back to the mid-1990s with. .. Connection Classes and Databases Connection Class Associated Database OdbcConnection OleDbConnection SqlConnection OracleConnection ODBC Data Source OLE DB Database SQL Server Database Oracle Database quite a few parameters to define a connection, but only five of them are popularly utilized for most data-driven applications: 1 Provider 2 Data source 3 Database 4 User ID 5 Password For different databases, the... developing and creating all sample databases we need to use later All of these sample databases will be utilized for different applications we will develop in this book Since the Oracle Database 10g XE is very different with other databases such as Microsoft Access and SQL Server 2005, you need to refer to Appendix F to get a clear picture about how to use the CSE_DEPT Oracle database files Refer to Appendix... the database as made up of tables, it is called a Network Model 6 Entity integrity rule states that no attribute that is a member of the primary (composite) key may accept a null value 7 When creating data tables for the Microsoft Access database, a blank field can be kept as a blank without any letter in it 8 To create data tables in SQL Server database, a blank field can be kept as a blank without... Utilities of Oracle Database 10g XE to Unload the five tables to five Text files, and how to Load those five table files into a new customer Oracle database to create a new customer Oracle database easily 2.12 CHAPTER SUMMARY A detailed discussion and analysis of the structure and components about databases were provided in this chapter Some key technologies in developing and designing databases were also... Figure 2.66 Our customer database creation for Oracle Database 10g Express Edition is completed A completed Oracle 10g XE sample database CSE_DEPT that is represented by a group of table files can be found in the folder Oracle located at the accompanying ftp web site (see Chapter 1) Refer to Appendix F to get more detailed information if you want to use this sample database in your Visual C# applications... data programming needs Combine this problem with the task of dealing with many different data stores, nonrelational data like XML and applications applying across multiple languages are challenging topics, and one should have a tremendous opportunity for complete rearchitecture The ADO.NET is a good solution for these challenges ADO.NET 2.0 was considered as a full solution between the relational database. .. was considered as a full solution between the relational database API and object-oriented data access API, which was released with the NET Framework 2.0 and Visual Studio.NET 2005 Today the updated version of the ADO.NET is 3.5, which is released with the NET Framework 3.5 and Visual Studio.NET 2008 In this chapter, first we will provide a detailed review about the history of ADO.NET, and then a full... Access, SQL Server 2005, and Oracle Database 10g XE were provided in detail All of these three sample databases will be used throughout the whole book HOMEWORK I True/False Selections 1 Database development process involves project planning, problem analysis, logical design, physical design, implementation, and maintenance 2 Duplication of data creates problems with data integrity 3 If the primary . Windows services. For the last decade, ADO has been the pre- Practical Database Programming With Visual C#. NET, by Ying Bai Copyright © 2010 the Institute of. sample databases will be utilized for different applications we will develop in this book. Since the Oracle Database 10g XE is very different with other databases

Ngày đăng: 26/01/2014, 08:20

Từ khóa liên quan

Mục lục

  • Practical Database Programming With Visual C#.NET

    • Contents

    • Preface

    • Acknowledgment

    • 1 Introduction

      • Outstanding Features of the Book

      • Target Audience

      • Topics Covered

      • Organization of the Book and How to Use It

      • How to Use the Source Code and Sample Databases

      • Instructor and Customer Support

      • Homework Solutions

      • 2 Introduction to Databases

        • 2.1 What Are Databases and Database Programs?

          • 2.1.1 File Processing System

          • 2.1.2 Integrated Databases

          • 2.2 Develop a Database

          • 2.3 Sample Database

            • 2.3.1 Relational Data Model

            • 2.3.2 Entity-Relationship Model (ER)

            • 2.4 Identifying Keys

              • 2.4.1 Primary Key and Entity Integrity

              • 2.4.2 Candidate Key

              • 2.4.3 Foreign Keys and Referential Integrity

              • 2.5 Define Relationships

                • 2.5.1 Connectivity

                • 2.6 ER Notation

Tài liệu cùng người dùng

Tài liệu liên quan