Download Introduction to ERwin

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

Relational algebra wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Database wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Ingres (database) wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Join (SQL) wikipedia , lookup

SQL wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

PL/SQL wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
IntroductiontoERwin
DatabaseDesign&Modelling
withStepbystepExercises
Hans-PetterHalvorsen,M.Sc.
DatabaseDesign– ERDiagram
ERDiagram(Entity-RelationshipDiagram)
• UsedforDesignandModelingofDatabases.
• SpecifyTablesandrelationship betweenthem(PrimaryKeysandForeignKeys)
TableName
Example:
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.if
needed.
CAERwinDataModelerCommunityEdition
• ToolforDatabaseModelling(ERDiagrams)
• Free!
• ForwardandReverseEngineeringwitha25object
limit
Downloadhere:
http://erwin.com/products/data-modeler/community-edition
ERwinExample
IntroductiontoERwin
OpenERwinandselectFile->New...
Thefollowing windowappears(NewModel):
Makesuretoselect
Logical/Physical Model
SelecttheDatabaseTypeandVersion youshalluse
IntroductiontoERwin
IntroductiontoERwin
Students:LettrytocreatethefollowingTables,Columns,
PrimaryKeysandForeignKeysusingERwin:
IntroductiontoERwin
How-To:CreateTablesandColumns
Usethe“Entity”Tool inorder
toCreateNewTables
Use<Tab>and<Enter>inordertogivethe
TablesaNameandtocreateColumns.
Usethe<Arrows>toswitchbetweenthe
Columns insideaTable
IntroductiontoERwin
How-To:CreatePrimaryKey(PK)– ForeignKey(FK)Relationships:
Usethe“Relationship”ToolinordertoCreateaPrimary Key
(PK) – Foreign Key(FK) Relationship
ClickfirstonthePKtableandthenontheFKtableusing the“Relationship”
Tool.TheRelationship Connection isthenCreatedAutomatically
IntroductiontoERwin
Makesuretoset
proper DataTypes
YoumayalsoDouble-click(orRight-clickand
selectTable/ColumnProperties) on Tables
andColumns inorder tochangedifferent
Attributes,eg.DataTypes,etc.
FinalResults:
How-To:CreateaSQLScript
IntroductiontoERwin
1
Select“ForwardEngineering ”
and“Schema...”
2
Makesureyou areusing
thePhysical Model
3
4
Select/DeselectdifferentOptions
inordertomakeyourscriptthe
wayyouwant.Click “Preview”in
ordertoseetheresults.
Click“Save”whenyouare
satisfied withyourScript
OpenSQLServerandcreate
a“NewDatabase...”
1
3
SQLServer
YouareFinished. Start
insertingsomtestdata,etc.
2
OpentheSQLScriptinorderto
inserttheTablesinSQLServer
DatabaseDesignExercise
Students: CreatethisExampleusing ERwin.
CreatetheTablesinSQLServer.
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorway
www.usn.no
E-mail:[email protected]
Blog:http://home.hit.no/~hansha/