Introductory thoughts about a DBMS:
What's the simplest way of storing data and retrieving it? I asked myself:
Store a few bytes of info in a simple ASCII file. Read and write using FileAPIs was the answer.
Well then if I want to store information pertaining to 10 employees in anorganization, I need to store employees information in a File.
I would need a 'field-delimiter':- to distinguish between the'Employee_Name' value and 'Employee_Number' value Then I would need a'record-delimiter':- to distinguish between different Employees. Then Iwould need a 'file-delimiter' :- to indicate the start and end of the file
A sample file can be:
"employee_name^employee_number-Mary^11111-Kindler^22222-Kitch^33333"
Here: '"' : Indicates the start and end of the data-file '^' : Field-delimiter '-' : Record-delimiter
(Simple scheme, assuming the 3 characters listed above do not appear asData!)
The rules to read data stored in the above format: 1. All data retrieved between a '"'(start) and a '-' (end) points to the Field-headers or column-names list 2. All data retrieved between a '-'(start) and a '-' (end) pointsto a Employee's Details. 3. All data retrieved between a '-'(start) and a'"' (end) points to the last record(Employee)'s details 4. First read thelist of column-names then, cycle through the list as you retrieve eachemployee's data. E.g.: read_emp_details(column_name,value);read_emp_details('employee_number',11111);
will allow us to retrieve all details for the employee withemployee_number = 11111
Now, I want to add a new employee to the list, and I want to ensure that hegets the highest employee_number and I also want to ensure that it isunique, I would have to read through my data file, reading each record'semployee_number, and once all employee_numbers are available, choose thehighest one among them, increment it, and then assign it to the newemployee. And the code for this would have to written.
Then, another piece of code that we might have to write, is to ensure that aemployee_number field has ONLY numbers(say), before each suchemployee_number is created the piece of code will have to be run tovalidate the new employee_number.
So we are basically 1.enforcing 'domain-integrity'(by checking for the range of VALID values) 2.Creating a data-storage format, 3.Creating a data-retrieval standard, 4.Enforcing data-integrity by checking for unique employee numbers
These are features we can find in a DBMS (DataBase Management System)
A DBMS is like a application with pre-coded rules to enforce data-integrityconstraints, domain constraints (i.e. in what values can be stored in avariable),proprietary data-storage and retrieval rules etc.
DBMS provide different data-types (NUMBER,VARCHAR2,BLOB..) that allow us toenforce such 'value-rules'/'domain-integrity' rules i.e. if a column isdeclared to be a NUMBER type,it can hold only a pre-defined range of values,any value above or below the range raises an exception.
We can look at DBMS as a kind of a 'service' software: In that, most issuesthat crop up while storing and retrieving data have been considered andappropriate solutions coded into the system. We query the DBMS for aservice: say for enforcement of a 'foreign- key' relationship. Writing freshapplication-specific code to enforce the 'foreign-key' relationship ispossible, but as the use of a application increases, and the data storedevolves, we'll have to constantly re-write the code. This can be avoided byusing a DBMS where the DBMS-writers have worked out such issues and coded itbefore hand.
When thinking of a database: it usually means a LARGE quantity of data,whether we are storing it in simple ASCII files or are using the latest DBMSavailable. Storing large quantities of data as simple ASCII files isinefficient, considering that today's compression/zipping utilities can cutby half the size of a simple ASCII file. It is here the proprietary data-storage formats of most DBMS fit-in. Every commercially available DBMSstores data in a highly-compressed format leading to better space usage, andin a way SECURE storage. 'Secure' because the data-format is proprietary,and often data stored in the data-file of a DBMS is highly distributed, i.e.information stored in a data-file might belong to 10 different users, eachhaving his own set of character-codes etc.
DBMS on the other hand can also be looked-at as a overkill. A simpleapplication might not need all the features offered in a DBMS, but then mostDBMS are written in such a way as to ensure that whatever feature of DBMS isused gets used in the most optimum manner.
DBMS programmers are 'query-writers' (what else!) : i.e. dbms programmersonly query the DBMS for data, they only KNOW what data they want, it is theDBMS that determines HOW the data will be retrieved. This is one way I liketo think of the plans that Oracle generates when it executes a query.
Sunday, January 13, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment