Professional Documents
Culture Documents
Submit Tips
Contact Us
Search
HOME
REVIEWS
HOW-TOS
CODING
INTERVIEWS
FEATURES
OVERVIEW
BLOGS
SERIES
IT ADMIN
Search for:
Search
As the title says, this is an introduction to databases, their purpose and features. It deals with how to design and create a simple database in MySQL. Starting off with the concepts of data and information, it is also a good read for those new to databases.
Its a Saturday morning, as I feed these words into a word processor. I have a browser running in the background, with a page on eBay open in one tab, and Engadget in another. The sheer simplicity of browsing through the product catalogues on eBay, or reading the latest and greatest tech news on Engadget, is living proof of the power of the database. The information age, the social networking age, the collaborative age, or whatever age you may want to call it, all revolve around data. Shouldnt the information age be revolving around, well, information? At this point, I would like to highlight a key difference between information and data. Information is processed data. From a philosophical standpoint, it has been wonderfully put by Gene Bellinger, Durval Castro and Anthony Mills in their article, aptly titled, Data, Information, Knowledge, and Wisdom; the cumulative order would be Data < Information < Knowledge < Understanding < Wisdom. As far as computing goes in day-to-day contexts, the buck stops at information databases, which, as the word suggests, deal with what underlies information, i.e., data. Consider the product page on eBay. All you see is information, the cohesive form, which consists of the product images, the description, the price, information about the seller, etc. The data is beneath this processed presentation in the browser. In this example, the individual components are data like the words in the description. The words, by themselves, cant stand independently on the page. Only when they are in context with one another, and with other data, do they convey something that makes sense. When they are processed, they turn into information. The domain of databases is vast, and fills volumes and volumes of mammoth publications. The scope of this article is to give you a taste and understanding of databases, how to go about designing one, and I will conclude with designing an actual but hypothetical database, and implementing it.
Databases are structures that hold data. The software that enables the flow of data through these structures is called a database management system or DBMS. The most widely used system of DBMS is something called RDBMS or Relational DBMS. This simply means that the data is stored in tables; moreover, whatever relationships that exist within the data are stored within tables. To put it simply, there are three parts that make a database: 1. Tables: We all know what tables are a matrix of rows and columns. In databases, its the same. Each row is a record, or a unit of data. A record (row) can have several columns or fields. Each field is like an attribute of that record. 2. Queries: A query is a question posed to the database, to retrieve a specific set of records, based on conditions supplied in the query. 3. Views: These are virtual tables, or (a set of) stored queries. At a physical level, the data is stored in data files specific to the DBMS. Examples of modern-day RDBMSs that are widely used include Oracle, MySQL, etc. Oracle is the largest commercially available RDBMS, and MySQL (earlier acquired by Sun, and subsequently by Oracle) is a free and open source RDBMS that is very well-known.
256,370 people like Open Source For You. Find us on Facebook
Follow
+2,530
Popular
Comments
Tag cloud
Here, the asterisk (* ) is synonymous to all its a wild-card character. The query will return all rows where the city is Mumbai. This SQL statement can be passed on to the RDBMS via an API function call in code, or through an application like phpMyAdmin. Upon receiving the query, the system returns the records as per the query. Suppose we want only names of the students from Mumbai, and not whole records (we dont want their addresses, phone numbers or countries of origin), the query would then become:
S E L E C Tn a m eF R O MS T U D E N T _ M A S T E RW H E R Ec i t y = ' M u m b a i ' ;
Note that the word Mumbai is in quotes because it is text. Numbers wont have quotes in a query. And the statement must end in a semi-colon. For the next part of this article, I will be using MySQL to create the database. Heres a quick way to go about installing and using it: Windows users: Download MySQL from its website (its called the MySQL Community Server). Just run the installer, and you should be okay. Linux users: Use the package manager and install m y s q l ; alternatively, you can build it from source, if you wish to. You can start MySQL through the command prompt (Windows) or terminal (Linux), by running m y s q lur o o tp . It will ask you for a password; keep it blank since the default is blank. You can change it later.
Designing a database
Heres where we design a database for some simple data. Lets say you want to make a database to store the names, addresses, phone numbers and birthdays of your friends and relatives. The first step is to see what kind of data you want to store: Names Addresses Phone Numbers Birthdays Lets begin by creating the database in MySQL:
m y s q l >C R E A T ED A T A B A S Em y c o n t a c t s ; Q u e r yO K ,1r o wa f f e c t e d( 0 . 0 0s e c ) m y s q l >U S Em y c o n t a c t s ; D a t a b a s ec h a n g e d
The U S Ecommand tells MySQL which database you want to be working on in this session. You can list the available databases using the following command:
m y s q l >s h o wd a t a b a s e s ; + + |D a t a b a s e | + + |i n f o r m a t i o n _ s c h e m a| |m y c o n t a c t s | |m y s q l | |p h p m y a d m i n | + + 4r o w si ns e t( 0 . 0 5s e c )
Now lets go table by table, and see what columns to put into each. These are the columns I put in:
1. Names: contact_id name 2. Addresses: contact_id address_line1 address_line2 city country email 3. Phone Numbers: contact_id landline mobile 4. Birthdays: contact_id birthdate So, we can now make four tables: N A M E S _ M A S T E R ,A D D R E S S _ M A S T E R ,P H O N E _ M A S T E Rand
B I R T H D A Y _ M A S T E R . The MySQL command for making N A M E S _ M A S T E Rwould be:
m y s q l >C R E A T ET A B L EN A M E S _ M A S T E R( c o n t a c t _ i dI N T , n a m eV A R C H A R ( 5 0 ) ) ; Q u e r yO K ,0r o w sa f f e c t e d( 0 . 1 4s e c )
Other tables can be made similarly. V A R C H A Rand I N Tare data-types. I N Tstands for integer. V A R C H A Ris a variable character. Its a dynamically changing field, whose size depends on the entered data. The V A R C H A R ( 5 0 )means the field can have a maximum size of fifty characters. Other supported data-types are listed in the MySQL documentation. Now lets explore the concept of primary and secondary keys. If you notice, the field c o n t a c t _ i d is common to all tables. This is to relate the tables by that common field. Here, the c o n t a c t _ i d in N A M E S _ M A S T E Ris the primary key, and the rest are secondary keys. In other words,
c o n t a c t _ i dis the reference for all the data in each table (as the secondary key), where it finally
relates to the name of the contact (as primary key). Once a table is made, you can populate it using a tool called phpMyAdmin. Doing justice to using phpMyAdmin would require another article; hence, I wont cover this aspect here. You can also populate using the I N S E R Tstatement:
I N S E R Ti n t ot a b l e _ n a m e( c o l u m n 1 ,c o l u m n 2 . . . ) v a l u e s( v a l u e 1 ,v a l u e 2 . . . ) ;
At the end of this exercise, you will have a database ready to use. This, frankly, is just the starting point in designing a database. I hope it proved helpful to you in understanding what goes on beneath the surface in cyberspace, at least when it comes to managing data.
Related Posts:
Connecting to MySQL with Python and PHP Installing and Using PostgreSQL Modules Database Programming in Python Lets Play with CodeIgniter FOSS is __FUN__: Get the Basics Right
Tags: acid, Amazon, Anthony Mills, API, database driver, database management system, Durval Castro, e commerce site, Gene Bellinger, information databases, interface driver, Java, jdbc, LFY May 2011, Murphy's Law, MySQL, odbc, Oracle, phpMyAdmin, product catalogues, RDBMS, SQL, Sun
Previous Post
Next Post
What's this?
India has immense under-utilised talent in the cloud 46 comments Cyber Attacks Explained: The Botnet Army 1 comment
Secure Your Career with Ethical Hacking! 3 comments GNOME Extensions Spicing Up the Desktop Experience 1 comment
C o m m e n t fe e d
Su b s cri b e vi a e m a i l
Reviews
How-Tos
Coding
Interviews
Features
Overview
Blogs
Search
Popular tags
Linux , ubuntu, Java, MySQL, Google, python, Fedora, Android, PHP, C, html, w eb applications , India, Microsoft, unix , Window s , Red Hat, Oracle, Security , Apache, xml, LFY April 2012, FOSS, GNOME, http, JavaScript, LFY June 2011, open source, RAM, operating systems
All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherw ise noted. LINUX For You is pow ered by WordPress, w hich gladly sits on top of a CentOS-based LEMP stack.