* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Database Modelling with ERwin
Relational algebra wikipedia , lookup
Tandem Computers wikipedia , lookup
Oracle Database wikipedia , lookup
Team Foundation Server wikipedia , lookup
Concurrency control wikipedia , lookup
Microsoft Access wikipedia , lookup
Functional Database Model wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
ContactPoint wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Clusterpoint wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
IntroductiontoERwin DatabaseDesign&Modelling Hans-PetterHalvorsen,M.Sc. Software ThefollowingEditionscanbedownloadedforFree onInternet: CAERwinDataModelerCommunityEdition SQLServerExpressEdition Overview 1.DesignandCreateTables 3.ExecutetheScriptwithinSQLServer 2.MakeaSQLScript 4.StartusingyourDatabase, InsertData,etc. DatabaseDesign& Modelling Hans-PetterHalvorsen,M.Sc. DatabaseDesign– ERDiagram ERDiagram(Entity-RelationshipDiagram) • UsedforDesignandModelingofDatabases. • SpecifyTablesandrelationship betweenthem(PrimaryKeysandForeignKeys) Example: TableName TableName Column Names PrimaryKey PrimaryKey ForeignKey RelationalDatabase.InarelationaldatabaseallthetableshaveoneormorerelationwitheachotherusingPrimaryKeys(PK)and ForeignKeys(FK).Note!YoucanonlyhaveonePKinatable,butyoumayhaveseveralFK’s. Database- “BestPractice” • Tables:Useuppercaseandsingular formintablenames– notplural,e.g., “STUDENT”(not“students”) • Columns:UsePascalnotation,e.g.,“StudentId” • PrimaryKey: • Ifthetablenameis“COURSE”,namethePrimaryKeycolumn“CourseId”, etc. • “Always”useInteger andIdentity(1,1) forPrimaryKeys.UseUNIQUE constraintforothercolumnsthatneedstobeunique,e.g.“RoomNumber” • SpecifyRequired Columns(NOTNULL)– i.e.,whichcolumnsthatneedtohave dataornot • Standardizeonfew/theseDataTypes:int,float,varchar(x),datetime,bit • UseEnglishfortableandcolumnnames • Avoidabbreviations!(Use“RoomNumber”– not“RoomNo”,“RoomNr”,...) DatabaseDesign&Implementation RecommendedSteps: 1. DatabaseModelling/DesignusingERwin 2. GenerateSQLTableScriptusingERwin(youmight needtoadjust/improveitinordertomakeitmore robust) 3. GenerateTablesinSQLServerusingtheSQLScript generatedbyERwin 4. CreateStoredProcedures,View,Triggers,etc.inside SQLServerifneeded. ERwin Hans-PetterHalvorsen,M.Sc. CAERwinDataModelerCommunityEdition • ToolforDatabaseModelling(ERDiagrams) • Free! • ForwardandReverseEngineeringwitha25 objectlimit Downloadhere: http://erwin.com/products/data-modeler/community-edition ERwinExample NewDatabaseModel OpenERwinandselectFile->New... Thefollowingwindowappears(NewModel): Makesuretoselect Logical/PhysicalModel SelecttheDatabaseTypeandVersionyoushalluse PageSetup Exercise LetstrytocreatethefollowingTables,Columns, PrimaryKeysandForeignKeysusingERwin: CreateTablesandColumns Usethe“Entity”Toolinorder toCreateNewTables Use<Tab>and<Enter>inordertogivethe TablesaNameandtocreateColumns. Usethe<Arrows>toswitchbetweenthe ColumnsinsideaTable CreatePrimaryKey(PK)– ForeignKey(FK)Relationships Usethe“Relationship”ToolinordertoCreateaPrimaryKey (PK)– ForeignKey(FK)Relationship ClickfirstonthePKtableandthenontheFKtableusingthe“Relationship” Tool.TheRelationshipConnectionisthenCreatedAutomatically SetDataTypes Makesuretoset properDataTypes YoumayalsoDouble-click(orRight-clickand selectTable/ColumnProperties)onTables andColumnsinordertochangedifferent Attributes,eg.DataTypes,etc. Attributes MoreTables... WecanextendourDatabaseDesign/Modellwith,e.g.: • AUTHOR • PUBLISHER • CATEGORY(e.g.,Programming,ControlSystems,..) ... (Youcantrythisonyourown) CreateSQLScriptswithERwin Hans-PetterHalvorsen,M.Sc. CreateSQLScript Select“ForwardEngineering” and“Schema...” 2 1 Makesureyouareusing thePhysicalModel 3 4 Select/DeselectdifferentOptions inordertomakeyourscriptthe wayyouwant.Click“Preview”in ordertoseetheresults. Click“Save”whenyouare satisfiedwithyourScript SQLServer ExecutetheSQLScriptwithinSQLServer Hans-PetterHalvorsen,M.Sc. MicrosoftSQLServer Software MicrosoftSQLServerManagementStudio 3 YourSQLServer 1 2 YourDatabase 4 WriteyourQueryhere Your Tables 5 TheResultsfromyourQuery MicrosoftSQLServer– CreateaNewDatabase 2 1 Nameyoudatabase accordingtoyourProject 1 OpenSQLServerand createa“NewDatabase...” SQLServer 3 YouareFinished.Startinserting sometestdata,etc. 2 OpentheSQLScriptinorder toinserttheTablesinSQL Server Identity(1,1) Hans-PetterHalvorsen,M.Sc. SettingtheIdentity(1,1) PropertyinERwin 1 2 3 Exercise Hans-PetterHalvorsen,M.Sc. DatabaseDesign&ModellingExercise CreatethisExampleusingERwin. CreateaScriptandexecuteitwithinSQLServer. Hans-PetterHalvorsen,M.Sc. UniversityCollegeofSoutheastNorway www.usn.no E-mail:[email protected] Blog:http://home.hit.no/~hansha/