Sunteți pe pagina 1din 6

DBMS As the name suggests, the database management system consists of two parts. They are: 1.

Database and 2. Management System What is a Database? To find out what database is, we have to start from data, which is the basic building block of any DBMS. Data: Facts, figures, statistics etc. having no particular meaning (e.g. 1, ABC, 19 etc). Record: Collection of related data items, e.g. in the above example the three data items had no meaning. But if we organize them in the following way, then they collectively represent meaningful information. Roll Name Age 1 ABC 19 Table or Relation: Collection of related records. Roll 1 2 3 Name ABC DEF XYZ Age 19 22 28

The columns of this relation are called Fields, Attributes or Domains. The rows are called Tuples or Records. Database: Collection of related relations. Consider the following collection of tables: T1 Name Age ABC 19 DEF 22 XYZ 28 T2 Address KOL DEL MUM T3 Year I II I T4 Hostel H1 H2

Roll 1 2 3 Roll 1 2 3 Roll 1 2 3 Year I II

We now have a collection of 4 tables. They can be called a related collection because we can clearly find out that there are some common attributes existing in a selected pair of tables. Because of these common attributes we may combine the data of two or more tables together to find out the complete details of a student. Questions like Which hostel does the youngest student live in? can be answered now, although Age and Hostel attributes are in different tables. In a database, data is organized strictly in row and column format. The rows are called Tuple or Record. The data items within one row may belong to different data types. On the other hand, the columns are often called Domain or Attribute. All the data items within a single attribute are of the same data type

Primary and Foreign key constraints are and what they are used for: Primary Key: A primary key is a field or combination of fields that uniquely identify a record in a table, so that an individual record can be located without confusion. Foreign Key: A foreign key (sometimes called a referencing key) is a key used to link two tables together. Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key (it remains a primary key in the original table). More complicated but fuller explanation: Employee Table EmployeeID (PK) 001 002 003 004 005 006 FirstName Stan Joe Mark Jenny Sally John LastName Smithers Bloggs Richards Lane Holmes Lee Department IT Support Sales Sales Marketing Sales IT Support Manager Stan Smithers Joe Bloggs Joe Bloggs Jenny Lane Joe Bloggs Stan Smithers

A primary key is the field(s) (a primary key can be made up of more than one field) that uniquely identifies each record, i.e. the primary key is unique for each record and the value is never duplicated in the same table, so in the above table the EmployeeID field would be used. A constraint is a rule that defines what data is valid for a given field. So a primary key constraint is a rule that says that the primary key fields cannot be null and cannot contain duplicate data. The problem with the above table is that you have repeating information in the manager field, this causes all sorts of problems, e.g. Fred Bloggs leaves and Jenny Smith becomes sales manager, you now have to replace all entries that say Fred Bloggs with Jenny Smith. If however you split the last two fields out to make a department table you would only need one entry for each department, when a manager changes you only need to make the change in one place, if you setup a primary key of DeptID in the department table you would have the following. Department Table DeptID (PK) 01 02 03 Department IT Support Sales Marketing Manager Stan Smithers Joe Bloggs Jenny Lane

Employee Table EmployeeID (PK) 001 002 003 004 005 006 FirstName Stan Joe Mark Jenny Sally John LastName Smithers Bloggs Richards Lane Holmes Lee

You now need to link the two table together so you know which department each employee is in, so what you do is take the primary key from the department table and insert it into the employee table (where it becomes a foreign key as a foreign key is the primary key from one table inserted into another table to link them). Employee Table EmployeeID (PK) 001 002 003 004 005 006 FirstName Stan Joe Mark Jenny Sally John LastName Smithers Bloggs Richards Lane Holmes Lee DeptID (FK) 01 02 02 03 02 01

A foreign key constraint specifies that the data in a foreign key must match the data in the primary key of the linked table, in the above example we couldn't set the DeptID in the Employee table to 04 as there is no DeptID of 04 in the Department table. This system is called referential integrity, it is to ensure that the data entered is correct and not orphaned (i.e. there are no broken links between data in the tables) The other added advantage is that you are saving space, if the following were the field sizes for the tables we have:

EmployeeID = 3 characters Firstname = 10 characters Surname = 10 characters Department = 10 characters DeptID = 2 characters Manager = 20 characters

The original Employee Table would take 53 characters per record, 6 records gives us 318 characters. The latest version of the Employee Table would take 25 characters, 6 records gives us 150 characters. The Department table would take 32 characters and there a 3 records so 96 characters, so 150+96 = 246 characters. So over a very simple structure with just 6 records we have saved ourselves 72 characters, which would be 72 Bytes.

Doesn't sound much on 6 records but if we had 600 employees the original system would take 53*600 = 31800 characters. Whereas the new system would take 25*600 = 15000 + 32*3 = 96 Which is a total of 15096 characters, a saving of 16704 characters so we have saved over 50% of the storage space.

Keeping organizational information in a conventional file-processing system has a number of major disadvantages. They are 1. Data redundancy and inconsistency: Since the files and application programs are created by different programmers over a long period, the various files are likely to have different formats and the programs may be written in several programming languages. Moreover, same information may be duplicated in several places. This redundancy leads to higher storage and access cost. In addition, it may lead to data inconsistency; that is, the various copies of the same data may no longer agree. 2. Difficulty in accessing data: Suppose the one of the bank officer needs to find out the names of all customers who live within the citys zip code is 630001. The officer asks the data processing department to generate such a list. Because this request was not anticipated when the original system was designed, there is no application program on hand to meet it. The point here is that conventional file-processing environment do not allow needed data to be retrieved in a convenient and efficient manner. More responsive data retrieval system must be developed for general use. 3. Data isolation: Because data are scattered in various files, and files may be in different formats, it is difficult to write new application programs to retrieve the appropriate data. 4. Integrity problems: The data values stored in the database must satisfy certain types of consistency constraints. For example, the balance of a bank account may never fall below a prescribed amount. Developers enforce these constraints in the system by adding appropriate code in the various application programs. However, when new constraints are added, it is difficult to change the programs to enforce them. 5. Atomicity problems: A computer system, like any other mechanical or electrical device, is subject failure. In many applications, it is crucial to ensure that, once a failure has occurred and has been detected, the data are restored to the consistent state that existed prior to the failure. The transfer of information must be atomic-it happen in its entirety or not at all. It is difficult to ensure this property in a conventional file-processing system. 6. Concurrent-access anomalies: So that the overall performance of the system is improved and a faster response time is possible, many systems allow multiple users to update the data simultaneously. In such an environment, interaction of concurrent updates may result in inconsistent data. To guard against this possibility, the system must maintain some form of

supervision. Because data may be accessed by many different application programs that have not been coordinated previously, supervision is difficult to provide. Security problems: Not every user of the database system should be able to access all the data. For example, in a banking system, payroll personnel need to see only that part of the database that has information about various bank employees. They do not need access to information about customer accounts. Since application programs are added to the system in ad hoc manner, it is difficult to enforce such security constraints.

S-ar putea să vă placă și