More Advanced SQL Statements - And along came baby (Page 3 of 5 )
Now that we've wedded some tables in unholy matrimony and made some babies, let's add to our amazing powers and learn the CREATE statement.
With the CREATE statement you can create new tables and even an entirely new database. Before we do however, let's discuss data types.
In short, the data type defines what sort of data a column can hold. If you signify that a field is a date field, and try to enter text into that field, your database will yell at you. Everything has a place, and put the proper things there. And close the door. What, were you born in a barn?
The following table shows the different data types available.
Data Type | Function |
CHAR | For character strings with a fixed-length |
VARCHAR | For character strings with variable lengths |
INT | For integer numbers |
Numeric | For holding numbers with decimals |
Float | For numbers with floating points |
Date | For dates |
Time | For times |
TIMESTAMP | For dates and times |
INTERVAL | For holding time intervals |
There are other forms of data types, but they are beyond the scope of this article. For the time being, these should suffice.
So now your boss wants a new database. This one will show the employees' names and how long they have been with the company. We will call this database Seniority. To create the database in SQL, do the following:
CREATE DATABASE SENIORITY;
It's just that simple. Or is it? Of course it isn't. We also need a table for our database. So let's create that now.
CREATE TABLE SENIORITY
(
EmployeeName VARCHAR,
YearsEmployed INT
)
Next: Speeding Up the Search >>
More BrainDump Articles
More By James Payne