版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、12010 Xiaojie YuanYuan XiaojieDept. of Computer Science and technology, Nankai UniversitySlides adapted from material by Profs. Jeff Ullman (Stanford) and Art Keller (UCSC)22010 Xiaojie Yuan cover mostly relational databases how to design and create such databases how to use them (via SQL query lang
2、uage) how to implement them (only briefly) will touch on some advanced issues XML data models, data warehouse, data mining32010 Xiaojie Yuan Must have data structure and algorithm background Good at C+,Java,C# project will require lot of programming need C+ or Java or C# to do a good job at talking
3、with databases you or your project group picks the language Knowing only C will require more work more difficult to talk in C to databases42010 Xiaojie YuanDatabase Systems: The Complete Book, Hector Garcia-Molina, Jeffrey D. Ullman, and Jennifer Widom, Prentice Hall, 2002.定价:65.00元北方区经理:余勇电话:010-68
4、995264.88379625七折,送书上门)遗憾:没有英文影印板发行52010 Xiaojie Yuan数据库系统概论萨师煊、王珊 高等教育出版社数据库系统原理王能斌 编著 电子工业出版社62010 Xiaojie Yuan“A First Course in Database System”, Jeffrey D.Ullman, Jennifer Widom 翻译版,数据库系统基础教程, 清华大学出版社“Database System Implementation”,Hector Garcia-Molina, Jeffrey D.Ullman, 翻译版,数据库系统
5、实现, 机械工业出版社 “Database System Concepts”,Third Edition, Fourth Edition, Abraham Silberschatz Henry F. Korth S. Sudarshan, 机械工业出版社 72010 Xiaojie YuanCS 145CS 245CS 346CS 345CS 347CS 395CS 545Fall, SpringWinterDB Systems ImplementationAdvanced TopicsTP + DDBsIndependent DB ProjectDB SeminarFallSpringSpr
6、ingAllFall, SpringA First Course in Database SystemDatabase System Principles82010 Xiaojie Yuan For all students two 70-min lectures / week (If you have conflicts, do let us know in advance, 5% ) 4 homeworks(Will be collected at the beginning of class on the due date,No late homework will be accepte
7、d, 10%) projects (10%) Midterm Examination( 15%, SQL, Computer) Final Examination Closed Book (60%) 92010 Xiaojie Yuan 讲稿放在学院服务器上 Instructor: yuan xiaojie Room 309, 伯苓楼伯苓楼 Email: Office hours: wed. 10:40-11:30 (after lecture) TAs: 林伟坚 cn安诚 官莹 102010 Xiaojie Yuan Suppose we a
8、re building a system to store the information about: students courses professors who takes what, who teaches what定义:定义:CTypedPtrList m_pDataList; 1 1 0 0 0 0 1 1 z z h h a a n n g g 1 1 0 0 0 0 2 2 w w a a n n g g 1 1 0 0 0 0 3 3 l l i i 1 1 0 0 0 0 4 4 z z h h a a o o m m _ _ p p D D a a t t a a L
9、L i i s s t t112010 Xiaojie Yuan store the data for a long period of time large amounts (100s of GB) protect against crashes protect against unauthorized use allow users to query/update: who teaches “CS 173” enroll “Mary” in “CS 311” allow several (100s, 1000s) users to access the data simultaneousl
10、y allow administrators to change the schema add information about TAs122010 Xiaojie Yuan Why Direct Implementation Wont Work: Storing data: file system is limited size less than 4GB (on 32 bits machines) when system crashes we may loose data password-based authorization insufficient Query/update: ne
11、ed to write a new C+/Java program for every new query need to worry about performance132010 Xiaojie Yuan Concurrency: limited protection need to worry about interfering with other users need to offer different views to different users (e.g. registrar, students, professors) Schema change: entails cha
12、nging file formats need to rewrite virtually all applications Better let a database system handle it142010 Xiaojie Yuan Data Definition Language - DDL Data Manipulation Language - DML query language Storage management Transaction Management concurrency control recovery152010 Xiaojie Yuan Requirement
13、s modeling (conceptual, pictures) Decide what entities should be part of the application and how they should be linked. Schema design and implementation Decide on a set of tables, attributes. Define the tables in the database system. Populate database (insert tuples). Write application programs usin
14、g the DBMS way easier now that the data management is taken care of.162010 Xiaojie YuanaddressnamefieldProfessorAdvisesTakesTeachesCourseStudentnamecategoryquarternamessncid172010 Xiaojie Yuan Tables: Separates the logical view from the physical view of the data.SSNNameCategory123-45-6789Charles und
15、ergrad234-56-7890DangradSSNCID123-45-6789CSE444123-45-6789CSE444234-56-7890CSE142Students:Takes:CIDNameQuarterCSE444DatabasesfallCSE541Operating systemswinterCourses:182010 Xiaojie Yuan Find all courses that “Mary” takes S(tructured) Q(uery) L(anguage) Query processor figures out how to answer the q
16、uery efficiently. select C.namefrom Students S, Takes T, Courses Cwhere S.name = “Mary” and S.ssn = T.ssn and T.cid = C.cid192010 Xiaojie YuanImperative query execution plan:select C.namefrom Students S, Takes T, Courses Cwhere S.name=“Mary” and S.ssn = T.ssn and T.cid = C.cidDeclarative SQL queryPl
17、an: tree of Relational Algebra operators, choice of algorithms at each operatorGoal:StudentsTakessid=sidsnamename=“Mary” cid=cidCourses202010 Xiaojie Yuan 实体联系数据模型 关系数据模型与关系模式设计 数据库语言SQL(含触发器和存储过程) 关系代数 数据存储与索引 查询执行与优化 系统故障对策 并发控制212010 Xiaojie Yuan Relational databases are a great success of theore
18、tical ideas. Big DBMS companies are among the largest software companies in the world. Oracle IBM (with DB2) Microsoft (SQL Server, Microsoft Access) Others $20B industry.222010 Xiaojie Yuan 1973年,Charles W.Bachman,”网状数据库之父”主持设计与开发了最早的网状数据库系统IDS推动和促成了数据库标准的制定 1981年,Edgar Frank Codd,”关系数据库之父” A relat
19、ional Model of Data for Large Shared Data Banks 1998年,James Gray或Jim Gray, 数据库技术和“事务处理”专家 完整性、安全性、并发性、故障恢复232010 Xiaojie Yuan Several aspects: Modeling and design of databases Database programming: querying and update operations Database implementation DBMS study cuts across many fields of Computer
20、Science: OS, languages, AI, Logic, multimedia, theory.242010 Xiaojie Yuan Suppose you are working on database project Step 0: pick an application domain we will talk about this later Step 1: conceptual design discuss with your team mates what to model in the application domain need a modeling langua
21、ge to express what you want ER model is the most popular such language output: an ER diagram of the app. domain252010 Xiaojie Yuan Step 2: pick a type of DBMS relational DBMS is most popular and is our focus Step 3: translate ER design to a relational schema use a set of rules to translate from ER t
22、o rel. schema use a set of schema refinement rules to transform the above rel. schema into a good rel. schema At this point you have a good relational schema on paper262010 Xiaojie Yuan Subsequent steps include implement your relational DBMS using a database programming language called SQL ordinary
23、users cannot interact with the database directly and the database also cannot do everything you want hence write your application program in C+, Java, ASP, etc to handle the interaction and take care of things that the database cannot do So, the first thing we should start with is to learn ER model
24、.272010 Xiaojie Yuan Gives us a language to specify what information the db must hold what are the relationships among components of that information Proposed by Peter Chen in 1976 What we will cover basic stuff constraints weak entity sets design principles282010 Xiaojie Yuan Entity = “thing” or ob
25、ject. Entity set = collection of similar entities. Similar to a class in object-oriented languages. Attribute = property of an entity set. Generally, all entities in a set have the same properties. Attributes are simple values, e.g. integers or character strings.292010 Xiaojie Yuan In an entity-rela
26、tionship diagram, each entity set is represented by a rectangle. Each attribute of an entity set is represented by an oval, with a line to the rectangle representing its entity set.302010 Xiaojie Yuan Entity set Beers has two attributes, name and manf (manufacturer). Each Beer entity has values for
27、these two attributes, e.g. (Bud, Anheuser-Busch)Beersnamemanf312010 Xiaojie Yuan A relationship connects two or more entity sets. It is represented by a diamond, with lines to each of the entity sets involved.322010 Xiaojie YuanDrinkersaddrnameBeersmanfnameBarsnamelicenseaddrSellsBars sell somebeers
28、.LikesDrinkers likesome beers.FrequentsDrinkers frequentsome bars.332010 Xiaojie Yuan The current “value” of an entity set is the set of entities that belong to it. Example: the set of all bars in our database. The “value” of a relationship is a set of lists of currently related entities, one from e
29、ach of the related entity sets.342010 Xiaojie Yuan For the relationship Sells, we might have a relationship set like:BarBeerJoes BarBudJoes BarMillerSues BarBudSues BarPetes AleSues BarBud Lite352010 Xiaojie Yuan A mathematical definition: if A, B are sets, then a relation R is a subset of A x B A=1
30、,2,3, B=a,b,c,d, R = (1,a), (1,c), (3,b)makes is a subset of Product x Company:123abcdA=B=makesCompanyProduct362010 Xiaojie YuanaddressnamessnPersonbuysmakesemploysCompanyProductnamecategorystockpricenameprice372010 Xiaojie Yuan one-one: many-one many-many123abcd123abcd123abcdmakesCompanyProduct3820
31、10 Xiaojie Yuan Show a many-one relationship by an arrow entering the “one” side. Show a one-one relationship by arrows entering both entity sets. In some situations, we can also assert “exactly one,” i.e., each entity of one set must be related to exactly one entity of the other set. To do so, we u
32、se a rounded arrow.392010 Xiaojie Yuan Consider Best-seller between Manfs and Beers. Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfs would be inappropriate. But a manufacturer has to have a best-seller (we assume they are beer manufacturers).ManfsBeersBest-seller4
33、02010 Xiaojie YuanHow do we model a purchase relationship between buyers, products and stores?PurchaseProductPersonStoreCan still model as a mathematical set (how ?)412010 Xiaojie YuanQ: what does the arrow mean ?A: if I know the store, person, invoice, I know the movie tooRentalVideoStorePersonMovi
34、eInvoice422010 Xiaojie YuanQ: what do these arrow mean ?A: store, person, invoice determines movie and store, invoice, movie determines personRentalVideoStorePersonMovieInvoice432010 Xiaojie YuanPurchaseWhat if we need an entity set twice in one relationship?ProductPersonStoresalespersonbuyerPerson4
35、42010 Xiaojie YuanPurchaseWhat if we need an entity set twice in one relationship?ProductPersonStoresalespersonbuyer452010 Xiaojie YuanPurchaseProductPersonStoredate462010 Xiaojie YuanPurchasePersonStoreProductStoreOfProductOfBuyerOfdate 472010 Xiaojie Yuan Modeled as a mathematical set Binary and m
36、ultiway relationships Converting a multiway one into many binary ones Constraints on the degree of the relationship many-one, one-one, many-many limitations of arrows Attributes of relationships not necessary, but useful482010 Xiaojie YuanProductnamecategorypriceisaisaEducational ProductSoftware Pro
37、ductAge Groupplatforms492010 Xiaojie Yuan Subclass = special case = fewer entities = more properties. Example: Ales are a kind of beer. Not every beer is an ale, but some are. Let us suppose that in addition to all the properties (attributes and relationships) of beers, ales also have the attribute
38、color.502010 Xiaojie Yuan Assume subclasses form a tree. I.e., no multiple inheritance. Isa triangles indicate the subclass relationship. Point to the superclass.512010 Xiaojie YuanBeersAlesisanamemanfcolor522010 Xiaojie Yuan In the object-oriented world, objects are in one class only. Subclasses in
39、herit properties from superclasses. In contrast, E/R entities have components in all subclasses to which they belong. Matters when we convert to relations.532010 Xiaojie YuanFinding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifi
40、es a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Domain constraints: peoples ages are between 0 and 150. General constraints: all others (at most 50 students enroll in a class)542010
41、 Xiaojie Yuan A key is a set of attributes for one entity set such that no two entities in this set agree on all the attributes of the key. It is allowed for two entities to agree on some, but not all, of the key attributes. We must designate a key for every entity set.552010 Xiaojie Yuan Underline
42、the key attribute(s). In an Isa hierarchy, only the root entity set has a key, and it must serve as the key for all entities in the hierarchy.BeersAlesisanamemanfcolor562010 Xiaojie YuanCoursesdeptnumberhoursroom Note that hours and room could also serve as a key, but we must select only one key.572
43、010 Xiaojie Yuan Every entity set must have a key why? A key can consist of more than one attribute There can be more than one key for an entity set one key will be designated as primary key Requirement for key in an isa hierarchy see book582010 Xiaojie Yuan Occasionally, entities of an entity set n
44、eed “help” to identify them uniquely. Entity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many-one relationships from E and include the key of the related entities from the connected entity sets.592010 Xiaojie Yuan name is almost a key for fo
45、otball players, but there might be two with the same name. number is certainly not a key, since players on two teams could have the same number. But number, together with the Team related to the player by Plays-on should be unique.602010 Xiaojie YuanPlayersTeamsPlays-onnamenamenumber Double diamond
46、for supporting many-one relationship. Double rectangle for the weak entity set.612010 Xiaojie Yuan A weak entity set has one or more many-one relationships to other (supporting) entity sets. Not every many-one relationship from a weak entity set need be supporting. The key for a weak entity set is i
47、ts own underlined attributes and the keys for the supporting entity sets. E.g., player-number and team-name is a key for Players in the previous example.622010 Xiaojie YuanofSectionofSection #Depts Key: (DeptCode)Courses Key: (Course #, DeptCode)Sections key: (Section #, Course #, DeptCode)Course #D
48、eptDeptCodeof inNameCourse632010 Xiaojie Yuan1. Be Faithful Design should reflect your (possibly vague) ideas of the data.2. Avoid redundancy.3. Limit the use of weak entity sets.4. Dont use an entity set when an attribute will do.642010 Xiaojie YuanPurchaseProductPersonPresidentPersonCountryTeaches
49、CourseInstructor652010 Xiaojie Yuan Redundancy occurs when we say the same thing in two different ways. Redundancy wastes space and (more importantly) encourages inconsistency. The two instances of the same fact may become inconsistent if we change one and forget to change the other, related version
50、.662010 Xiaojie YuanBeersManfsManfBynameThis design gives the address of each manufacturer exactly addr672010 Xiaojie YuanBeersManfsManfBynameThis design states the manufacturer of a beer twice: as an attribute and as a related manfaddr682010 Xiaojie YuanBeersnameThis design repe
51、ats the manufacturers address once for each beer; loses the address if there are temporarily no beers for a manufacturer.manfmanfAddr692010 Xiaojie YuanMoviesDirectorsDirected-byYearDirs NameProfileNameGoodMoviesYearDirs NameDirs ProfileNameBad702010 Xiaojie YuanAn entity set should satisfy at least
52、 one of the following conditions:It is more than the name of something; it has at least one nonkey attribute.orIt is the “many” in a many-one or many-many relationship.712010 Xiaojie YuanBeersManfsManfBynameManfs deserves to be an entity set because of the nonkey attribute addr.Beers deserves to be
53、an entity set because it is the “many” of the many-one relationship ManfBaddr722010 Xiaojie YuanBeersnameThere is no need to make the manufacturer an entity set, because we record nothing about manufacturers besides their name.manf732010 Xiaojie YuanBeersManfsManfBynameSince the manufacturer is nothing but a name, and is not at the “many” end of any relationship, it should not be an entity 742010 Xiaojie Yuan Beginning database d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乡村一体化工作制度
- 五四八小时工作制度
- 乡安办分管工作制度
- tdk公司工作制度
- 代煎工作制度及流程
- 办公室办文工作制度
- 加拿大政府工作制度
- 劳动法课堂工作制度
- 医学生实习工作制度
- 医药办公室工作制度
- 雨课堂学堂云在线《高级医学英语(首都医大 )》单元测试考核答案
- 客户订单管理SOP文件
- 初中物理欧姆定律(教学课件)2025-2026学年初中物理人教版(2024)九年级全一册
- 肿瘤患者的营养评估及指导
- 成都存量房合同(标准版)
- 小学科学国培汇报
- 制造业安全知识培训模板课
- 服装生产线平衡分析与仿真优化研究
- DB13∕T 5603-2022 工贸行业非高危建设项目安全设施“三同时”报告编制导则
- 纯化水管道施工方案及钝化记录
- 售后服务管理师培训课件
评论
0/150
提交评论