Database Table Basics
A relational database system contains one or more objects called tables.
The data or information for the database are stored in these tables.
Tables are uniquely identified by their names and are comprised of columns
and rows. Columns contain the column name, data type, and any other
attributes for the column. Rows contain the records or data for the
columns. Here is a sample table called "weather".
city, state, high, and low are the columns. The rows contain the data
for this table:
| Weather |
| city | state | high | low |
| Phoenix | Arizona | 105 | 90 |
| Tucson | Arizona | 101 | 92 |
| Flagstaff | Arizona | 88 | 69 |
| San Diego | California | 77 | 60 |
| Albuquerque | New Mexico | 80 | 72 |
Source
More:
Creating Tables in Microsoft SQL Server - A good slide show tutorial
Understanding SQL Relational Databases
So what is a 'relational' database, and how does it use these tables? Well, a relational database lets us 'relate' data from one table to another. Let's say for example we were making a database for a car dealership. We could make one table to hold all of the details for each of the cars we were selling. However, the contact information for 'Ford' would be the same for all of the cars they make, so we do not need to type that data more than once.
What we can do is create a second table, called manufacturers. In this table we could list Ford, Volkswagen, Chrysler, etc. Here you could list the address, phone number and other contact information for each of these companies. You could then dynamically call the contact information from our second table for every car in our first table. You would only ever have to type this information once despite it being accessible for every car in the database. This not only saves time but also valuable database space as no piece of data need be repeated.
Source
SQL Data Types
Each column can only contain one type of data which we must define. An example of what this means is; in our age column we use a number. We could not change Kelly's entry to "twenty-six" if we had defined that column to be a number. The main data types are numbers, date/time, text, and binary. Although these have many subcategories, we will just touch on the most common types that you will use in this tutorial.
INTEGER- This stores whole numbers, both positive and negative. Some examples are 2, 45, -16 and 23989. In our example, the age category could have been integer.
FLOAT- This stores numbers when you need to use decimals. Some examples would be 2.5, -.664, 43.8882, or 10.00001.
DATETIME- This stores a date and time in the format YYYY-MM-DD HH:MM:SS
VARCHAR- This stores a limited amount of text or single characters. In our example, the name column could have been varcar (short for variable character)
BLOB- This stores binary data other than text, for example file uploads.
Source