IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Database Chapters.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
Module 2 Working with Data Types. Module Overview Using Data Types Working with Character Data Converting Data Types Working with Specialized Data Types.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
IMS 6217: Primary Key Reference 1 Dr. Lawrence West, MIS Dept., University of Central Florida Primary Keys Uniqueness of Table Rows Identifier.
Common Field Types Primary Key Descriptive Fields Foreign Key.
CPS120: Introduction to Computer Science
IMS 4212: Normalization 1 Dr. Lawrence West, Management Dept., University of Central Florida Normalization—Topics Functional Dependency.
Sizing Basics  Why Size?  When to size  Sizing issues:  Bits and Bytes  Blocks (aka pages) of Data  Different Data types  Row Size  Table Sizing.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
IMS 4212: Data Modeling—Attributes 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains Nonkey.
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
DAT602 Database Application Development Lecture 2 Review of Relational Database.
Data Types Lesson 4. Skills Matrix Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
IMS 4212: Data Manipulation 1 Dr. Lawrence West, MIS Dept., University of Central Florida Additional Data Manipulation Statements INSERT.
Conversion Functions.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Sql DDL queries CS 260 Database Systems.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
(Winter 2016) Instructor: Craig Duckett Lecture 13: Thursday, February 18 th Mere Mortals: Chap. 9 Summary, Team Work 1.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
IMS 4212: Data Modeling—Business Rules 1 Dr. Lawrence West, Management Dept., University of Central Florida Business Rules—Topics Intro.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
IMS 6217: Database Design & Entities 1 Dr. Lawrence West, MIS Dept., University of Central Florida Database Design--Topics DB Design.
IMS 4212: Normalization 1 Dr. Lawrence West, Management Dept., University of Central Florida Normalization—Topics Functional Dependency.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
What is your Character Data Type? March 5, 2016 John Deardurff Website:
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Standards and Conventions
Creating Database Objects
Databases Chapter 9 Asfia Rahman.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
Module 2: Creating Data Types and Tables
Data Definition and Data Types
Attributes and Domains
Ouch! Our Data Type Choices Did THAT?
Proper DataType Usage = Guaranteed Better Performance and Accuracy
What is your Character Data Type?
Working with Data Types
Database systems Lecture 2 – Data Types
PT2520 Unit 5: Physical Design
Attributes and Domains
Attributes and Domains
Creating Database Objects
Presentation transcript:

IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains Attribute Data Types –Numeric Data Types –Text Data Types –Date Data Types –Other Data Types Domain Constraints

IMS 4212: Data Modeling—Attributes and Domains 2 Dr. Lawrence West, Management Dept., University of Central Florida Non-key Attributes Previous discussion has focused on different kinds of attributes –Primary keys –Foreign keys –Alternate keys (candidate keys) We have implied and sometimes illustrated other attributes –Attributes that just contain information we want to record about an entity –Do not serve as any sort of key

IMS 4212: Data Modeling—Attributes and Domains 3 Dr. Lawrence West, Management Dept., University of Central Florida Non-key Attributes (cont.) Four major issues with non-key attributes –Identifying descriptive attributes –Placing attributes in the correct entity Rules of normalization Appropriate functional dependency –Identifying the appropriate data type for the attribute (field) –Specifying appropriate domain business rules for the attribute (field)

IMS 4212: Data Modeling—Attributes and Domains 4 Dr. Lawrence West, Management Dept., University of Central Florida Attribute Data Types When attributes are instantiated in a database they become fields Fields must have a data type –Similar to variable type in programming –(Variants are not allowed) Data type specifies: –Class of data (numeric, text, date, binary, other) –Size of data within the class

IMS 4212: Data Modeling—Attributes and Domains 5 Dr. Lawrence West, Management Dept., University of Central Florida Attribute Data Types (cont.) A field’s type supports processing and storage efficiency –Storage The number 123 can be represented with one byte The text “123” requires three bytes –Processing “123” must be converted to a number before it can be used in an arithmetic calculation The number 123 can be used directly in an arithmetic calculation

IMS 4212: Data Modeling—Attributes and Domains 6 Dr. Lawrence West, Management Dept., University of Central Florida Attribute Data Types (cont.) Many DB operations require comparisons of values Computers perform numeric operations (comparisons and arithmetic) much more efficiently than textual comparisons or text operations But a tremendous amount of useful business data is textual Date values are stored and compared as numbers but displayed as conventional dates Choose the appropriate data type for your attribute

IMS 4212: Data Modeling—Attributes and Domains 7 Dr. Lawrence West, Management Dept., University of Central Florida Attribute Data Types (cont.) Some special cases –Leading zeros in numbers ‘Numeric’ fields such as zip codes and social security numbers can start with zeros Storing them as numbers will strip off the leading zeros Store as text to retain leading zeros (And you will rarely perform arithmetic on them) –International implications Many countries use letters in their postal (zip) codes

IMS 4212: Data Modeling—Attributes and Domains 8 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types in SQL Server 2000 Integers –bigintIntegers from -2^63 to 2^63 – 1(8 bytes) –intIntegers from -2^31 to 2^31 – 1(4 bytes) –smallintIntegers from -2^15 to 2^15 – 1(2 bytes) –tinyintIntegers from 0 to 255(1 byte) Note: only positive for tinyint –bit0 or 1 only Used for boolean values No True/False data type in SQL Server

IMS 4212: Data Modeling—Attributes and Domains 9 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types in SQL Server 2000 (cont.) Decimal numeric values –Money and SmallMoney are the workhorses of business programming –money ± 2^63 (~ ± 922 trillion) decimal point fixed to four digits (1/10,000) no monetary formatting ($ or commas) –smallmoney+/- 214, fixed to four places

IMS 4212: Data Modeling—Attributes and Domains 10 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types in SQL Server 2000 (cont.) Decimal numeric values –Decimal or Numeric types are equivalent –Allow specifying large values of decimal precision –approximate range +/- 10^38 –decimal point can be anywhere in the value –Decimal(p, s) p=1-38: Number of digits represented s<p: Digits right of decimal place p affects storage size—examples: –p<=9  5 Bytes –29 <= p <=38  17 Bytes

IMS 4212: Data Modeling—Attributes and Domains 11 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types in SQL Server 2000 (cont.) Decimal numeric values (cont.) –Float and Real Values stored in scientific notation Float(n) where n=number of digits in coefficient These are very imprecise Not commonly used in business

IMS 4212: Data Modeling—Attributes and Domains 12 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Precision The type of numeric field also limits the size of calculated results on that field You might choose tinyint for a quantity field in a retail application If all quantities are summed and the result exceeds 255 the result will be limited to 255 There is a hierarchy of precedence for data type conversions –E.g., Money_value * SmallMoney_value gives a Money_value –TinyInt + SmallInt gives a SmallInt

IMS 4212: Data Modeling—Attributes and Domains 13 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Precision (cont.) Date Precedence –DateTime –SmallDateTime Character Precedence –nText –Text –nVarChar –VarChar –Char Numeric Precedence –Float –Real –Decimal –Money –SmallMoney –BigInt –Int –SmallInt –TinyInt –Bit

IMS 4212: Data Modeling—Attributes and Domains 14 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Precision (cont.) Uncomment each pair of SET/SELECT statements and see results Int = 1000 = = AS int)

IMS 4212: Data Modeling—Attributes and Domains 15 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types in SQL Server 2000 (cont.) Identity attributes –int and bigint attributes can be identity attributes –The field’s value for the first record will be automatically set to the identity seed value I usually set to 1,000 (int) or 10,000 (bigint) –Each new record will get a new value incremented by the identity increment Almost always one –Widely used for PKs –Foreign Keys will be the same data type but will not be an identity attribute

IMS 4212: Data Modeling—Attributes and Domains 16 Dr. Lawrence West, Management Dept., University of Central Florida Numeric Data Types (cont.) BigInt± 9,223,372,036,854,775,808 Int± 2,147,483,648 SmallInt± 32,768 TinyInt (positive only) Decimal ± 10^38 Money ± 922,337,203,685, SmallMoney +/- 214,

IMS 4212: Data Modeling—Attributes and Domains 17 Dr. Lawrence West, Management Dept., University of Central Florida Date Data Types in SQL Server 2000 datetime –January 1, 1753 to December 31, 9999 –Accurate to 3 hundredths of a second smalldatetime –January 1, 1900 to June 6, 2079 –Accurate to one minute –Remember the year 2000 problem Required time precision (rather than maximum date allowed) may determine datatype chosen Use “___Date” or “___Time” in naming to indicate stored precision

IMS 4212: Data Modeling—Attributes and Domains 18 Dr. Lawrence West, Management Dept., University of Central Florida Text Data Types in SQL Server 2000 Unicode vs. nonUnicode –Unicode allows the extended character set needed to represent many foreign, especially Oriental, languages –Unicode uses two bytes per character –nonUnicode limited to 255 characters and supports most European languages Text/character fields are specified with their maximum length

IMS 4212: Data Modeling—Attributes and Domains 19 Dr. Lawrence West, Management Dept., University of Central Florida Text Data Types in SQL Server 2000 char(n)up to 8,000 characters –Fixed length text field n characters long –Shorter values will be padded with spaces –Wasted space but efficient processing –May require trimming when retrieving varchar(n)up to 8,000 characters –variable length text field n characters long text(n)up to 2,147,483,647 characters –Variable length text field allows for large text fields –May not be searched with SQL comparisons

IMS 4212: Data Modeling—Attributes and Domains 20 Dr. Lawrence West, Management Dept., University of Central Florida Text Data Types in SQL Server 2000 (cont.) nchar(n), nvarchar, ntext are Unicode versions of char, varchar, and text data types Don’t be stingy declaring text fields but don’t be wasteful, either –char data types can blow up database size quickly –varchar and text fields can require additional processing Avoid searching within long text values unless necessary Full text indexing is available in SQL Server and other databases

IMS 4212: Data Modeling—Attributes and Domains 21 Dr. Lawrence West, Management Dept., University of Central Florida Other Data Types in SQL Server 2000 binary, varbinary, and image are three different data types that store binary values –images –formatted documents such as Excel or Word documents –Avoid storing binary data in the database uniqueidentifier is a field that automatically creates a value guaranteed to be unique anywhere in the world See text for info on cursor, rowversion, and sql_variant –Don’t even think about using sql_variant for normal business data design

IMS 4212: Data Modeling—Attributes and Domains 22 Dr. Lawrence West, Management Dept., University of Central Florida Data Type Considerations The attribute data types are also the same datatypes available for use in stored procedures –Parameters –Variables Ensure that variable/parameter data type is consistent with its use –Will hold required value –Is consistent with field datatypes with which it is compared Int

IMS 4212: Data Modeling—Attributes and Domains 23 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints Domain constraints are critical limitations on the values that attributes can take on –Is a value required? Always for PK attributes What about other attributes? –Is value numeric, textual, boolean, date? –Are there ranges the value must be in or must not be in? –Are there limited choices for the value (e.g., subtype identifier codes, state abbreviations) –Other examples

IMS 4212: Data Modeling—Attributes and Domains 24 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints (cont.) Some domain constraints are simple –Last names may not be null and must be alphabetic characters between two and 30 characters in length Some domain constraints can be more complex –Social security numbers will be recorded as character strings with three numeric characters, a dash, two numeric characters, a dash, and four numeric characters and will be exactly eleven characters long

IMS 4212: Data Modeling—Attributes and Domains 25 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints (cont.) Many domain constraints contain ranges –Minimum or maximum values Numbers Dates –Price must be greater than zero and less than 10,000 –Membership date must be after 6/6/55 Domain constraints may specify a default value –Quantity defaults to 1 –Purchase date defaults to current date

IMS 4212: Data Modeling—Attributes and Domains 26 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints (cont.) Some domain constraints can be expressed in terms of calculated values when calculations refer to system values –Birth date must be more than 21 years earlier than today More complex calculations to enforce business rules are implemented as operational constraints (triggers) –Inventory quantity on hand is the sum of all items received less the sum of all items sold less the sum of all inventory adjustments –Covered in the next lesson

IMS 4212: Data Modeling—Attributes and Domains 27 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints Identifier Attributes (Primary Keys) will have special domain constraints –Cannot be null –Single attribute identifiers must be unique –Composite identifiers must be unique (though each component attribute will not be) Some other attributes or sets of attributes may also be set to be unique –SSN and driver's license number in the same entity –Use an Index required to be unique to implement

IMS 4212: Data Modeling—Attributes and Domains 28 Dr. Lawrence West, Management Dept., University of Central Florida Domain Constraints (cont.) Two ways to implement domain constraints –Specify each aspect of the domain for each attribute –Specify named domains (rules) A "Last Name" domain may have all the rules for last name attributes Different entities with last name attributes would use the named domain for those attributes E.g., Salesrep, Employee, Customer, Supplier DBMS must support named domains (called rules in SQL Server) Bind rule to a column