Description: Description: Description: Description: Description: Description: Description: Description: E:\banner.gif

 

Introduction to Data Structures

 

 

 

We deal with data all the time. How we store, organize and group our data together is the subject of data structures, and is of fundamental importance when it comes to using databases efficiently. Data structure is the most fundamental and building block concept in databases. A good knowledge of data structures is a must to design and develop efficient databases. Let us consider some examples from our day-to-day life, where organizing data in a particular structure helps us. We are able to search for a word quickly and efficiently in a language dictionary because the words in a dictionary are sorted. What if the words in the dictionary were not sorted? It would be impractical and impossible to search for a word among millions of words. So a dictionary is organized as a sorted list of words.

Let us consider another example. If we have a city map, the data like positions of landmarks, and road network connections is organized in the form of geometries. We show this map data in the form of geometries on a two-dimensional plane. Map data needs to be structured like this so that we have scales, so that we can measure distances and directions, and we are effectively able to search for a landmark, and get routed from one place to another.

Consider yet another example. A daily cash-in and cash-out statement of a business organization (what is also called a cash book in accouning parlance), makes most sense when organized in the form of a tabular schema. It becomes very easy to aggregate data and extract information if the data is organized in rows and columns in a tables.

All these examples demonstrate that different kinds of structures are needed to organize different kinds of data. Computers work with all kinds of data. They work with numbers, text, images, videos, relational data, geospatial data and pretty much any kind of data that we have on this earth. How we store, organize and group data in computers matters because computers deal with really large data. Even with the computational power of these machines, if we do not use the right kind of data structures - the right kind of logical structures - then our databases will not be efficient. Data types are classifications that identify possible values for and operations that can be done on the data. So a formal definition of data structures would be that a data structure is a way of organizing and storing data in a format that allows specific data types or range of values to be grouped together, so that the data can be used efficiently.

When you design a database you need to create a schema to explain what type of data will be stored in which field. This is called the structure of the database, and is also referred to as the schema or dictionary. Before creating a database, you need to think about its purpose. What is the database going to be used for? What searches might be performed on it? Each field in the database is created for a specific data type which also determines the way in which the data in that field is stored in the database.

Data types are also used by database applications. The fields within a database often require a specific type of data to be input. For example, a company's record for an employee may use a string data type for the employee's first and last name. The employee's date of hire would be stored in a date format, while his or her salary may be stored as an integer. By keeping the data types uniform across multiple records, database applications can easily search, sort, and compare fields in different records.

While designing a database, there are key areas to consider about the data:

        Data type - the data that is required to be stored in each field

        Field size - the maximum or minimum size of entry

        Validation - the rules for accepting data

        Key field - the field which is the primary key

The data types commonly supported by most databases (such as Oracle, MySQL, MS SQL ) can be divided into different categories as given below:

Data Type

Used for

Example

String

Ordered sequence of alphanumeric characters

hello world, Alice, Bob123, abc, def456, 3erf78!@

Integer

Whole numbers

7, 12, 999

Float (floating point)

Number with a decimal point, sometimes called real numbers, or floats

3.15, 9.06, 00.13

Character

Encoding text numerically

97 (in ASCII, 97 is a lower case 'a')

Boolean

Representing logical values

TRUE, FALSE, AND, OR, NOT

Binary

Store large amount of binary data. Max length is up to 2 GB

Descriptive text, image or sound data

Date

Used to store date and time.

DD.MM.YY, DD.MM.YYYY etc.

In the database programming language, the data types can be set as follows:

Data Type

Explanation

Char(size)

Fixed-length character string. Size is specified in brackets.

Varchar(size)

Variable-length character string. Maximum size is specified in brackets.

Integer(size)

Number value with a maximum number of column digits specified in brackets.

Date

Date value

Float(size,d)

Number value with a maximum number of digits of 'size' total, with a maximum number of 'd' digits to the right of the decimal.

Boolean

True/False values.

The data type defines which operations can safely be performed to create, transform and use the variable in another computation. When a program language requires a variable to only be used in ways that respect its data type, that language is said to be strongly typed. This prevents errors, because while it is logical to ask the computer to multiply a float by an integer (1.5 x 5), it is illogical to ask the computer to multiply a float by a string (1.5 x Alice). When a programming language allows a variable of one data type to be used as if it were a value of another data type, the language is said to be weakly typed.

Description: Description: Description: Description: Description: Description: Description: Description: E:\vine1.gif

Notes & Handouts

The Himalayas

Kumaon Himalayas

Askot Basemetals

University


This website is hosted by

S. Farooq

Department of Geology

Aligarh Muslim University, Aligarh - 202 002 (India)

Phone: 91-571-2721150

email: farooq.amu@gmail.com