Chapter 12 Representing Data Elements • CS257 Spring 2008 • Instructor: Dr.Lin • Jindou Jiao Contents • Data Elements and Fields – Representing Relational Database Elements – Representing Objects – Representing Data Elements • Attributes need to be represented by sequences of bytes, called ”field”. • Fields are put together called “records”. • Records need to be stored in physical blocks. • A collection of records form a relation. Representing Relational Database Elements • Relational database refers to a database’s data and schema. • DBMS has to represent and store the relation described by the declaration. – Consider the MovieStar relation below declared in SQL CREATE TABLE MovieStar ( name CHAR(30) PRIMARY KEY, address VARCHAR(255), gender CHAR(1), birthdate DATE ); • Issues in representing relational DB elements – How to represent SQL datatypes as fields – How to represent tuples as records – How to represent collections or records in blocks of memory – How to represent and store relations as collections of blocks – How to cope with record sizes – What if the size of a record changes due to updating Representing Objects • Object is a tuple, and its instance variables are attributes. • Objects can have methods or special-purpose functions associated with them. • Objects may have an object identifier(OID), which is an address that refers uniquely to that object. Pointers are used to related objects with each other. Representing Data Elements • Datatypes are represented in attributes of a record • Fixed-Length Character Strings – CHAR(n): n bytes • Pad characters are used if the actual value is shorter than n • Variable-Length Character Strings – VARCHAR(n): n+1 bytes • Length plus content: # of bytes in the string + characters of the string • Null-terminated string: characters of the string + “null” character Representing Data Elements (con.) • Dates and Times – Date: 10 bytes (YYYY-MM-DD) – Time: 8 bytes (HH:MM:SS) – May need more bytes to include fraction of a second • Bits – Store a sequence of bits • Enumerated Type