Introduction to SQL
| The term SQL stands for structure query language. It consists of a set of command that humans use to instruct a computer to store, modify and retrieve information.
This posting and a few more to come will discuss the commands used to create/allocate storage space, how data is stored, modified, retrieved, erased and secured. The next few postings on the subject will also talk about why it is important for every business to acquire, store, retrieve, accurately interpret and secure such information.
Creating a Database:
Before any user data can be stored in what is called a "Relational database system, you need to create a space to store related information. This space is what is called a database, which is basically a collection of entities called tables and relationships among those entities.
To create a database, we use the following SQL command/statement:
create database db_name; where db_name is the name of your database.
Once you have a database, you can now start creating your data entities. I am assuming that you have already identified these data entities and attributes or features that are important to your business.
For example: You own a business that rent out books. Your business process requires you to keep track of which book is in stock, which is borrowed and by who, when you expect your books to be returned and so forth.
To be able to keep this information without having to duplicate the information every time a book is borrowed or returned, you will need to identify entities for which you want to keep information. The information in these entities will then only be recorded once.
In this case we know that we want to keep information about borrowers and information on every book that belong to your business. In addition to this, you want to keep information on the borrowing process itself; such as transaction date, when you expect the books to be returned, the condition of the book when borrowed and its return condition and so forth; which we consider to be attributes of the borrowing entity.
In SQL terms we would define the borrower entity as follows:
Create table entity_name(
borrower data type,
booknumber data type,
borroweddate data type,
returndate data type,
borrowcondition data type,
returncondition data type);
where data type is one of the following:
1) integer,
2) varchar
3) text and so fort...
Now that we have our first entity is created, we have to start adding data to it, this happens when for example somebody comes in to borrow a book. To add data to an entity, we use the insert command. This is expressed as follows:
insert into borrowing(borrower,booknumber,borrowdate,returndate,borrowcondition,returncondition)
values(value1,value2,value3,value4,value5,value6);
Note: the number and type of values have to match the specified fields or attributes, otherwise it won't work. In some cases you may skip specifying the attributes you want to add; if you do then you have to make sure the values match the order and type of attributes in that entity or table.
Now that you have information stored, how do you retrieve it? In other words say, you want to know who borrowed what book.
To do this you would use the select command or statement to request the information. Bellow is how you do it:
Select * from borrowing;
The statement above tells the database system to return everything that is stored in the table named borrower .
You can also choose just to get part of the information stored in the table. For example, if you only want to see the borrower and the date on which they borrowed the book, you would do the following:
Select borrower, borroweddate from borrowing in which case, we are telling the system to give us data in the two fields/attributes (borrower and borroweddate).
|
RELATED ARTICLES: Creating database tables with SQL To create a table in SQL, you use a command that requires the name of the table as well as names and data types of the fields of that table. In general, the syntax for creating a table is as follows:
CREATE table_name ( column_name data_type);
The table nam
Creating and dropping SQL Views
In SQL, a view is like a virtual table. It be haves like a table except it does not store any data. Meaningful use of a view is usually to gather and simplify presentation of data from multiple tables. A view is compiled once and is stored on the database server and can be used wh
Creating your business web site There are thousands of business websites on the World Wide Web. These websites serves as a means to inform your customers, suppliers, media contacts and other interested parties about your business and its offerings. Thus it is important to deliver essential information in a wa
Introduction to Accounting
Introduction to Operations Management Operations management encompasses the process of how businesses produce goods and/or services. This involves responsibilities, activities and decisions of those tasked with managing production processes. Almost everything we use, eat or wear is made somewhere, possibly a manufacturing plant or simil
Introduction to HTML HTML is a computer language used to create websites. The fact that you are looking at this page, means you are also looking at the outcome of html code. It is relatively easy to learn, with the majority of what you really need to know being readily available and for free on the internet.
Introduction to Programming What exactly is programming?
Programming can be defined as the art of telling a computer to do whatever you want it to. If you are reading this posting you probably started off with switching the computer on and then opened the browser that got you to this page.
Every comp
Selecting data from multiple tables So far we have covered methods of retrieving data from single table. In real life however, you hardly get to only retrieve data from one table. In other words, to retrieve and interpret information, you normally get such information from different tables each of which will contain only information a
Introduction to Geometry By definition geometry is considered to be the study of space, shapes and their configurations. Almost every one of us use geometry on a daily basis ranging from computer scientist, to engineers to less sophisticated and ordina
The state of Periodic table elements - In addition to the group 8 or O elements, the following elements also naturally occur in gas state:
H, N, O, F, Cl and Br
-Among metals and non-metals, the following occurs in liquid state:
Na, K, Rb, Cs, Fr, Hg a
| |
|