Before we write any code, let's create a simple database. We'll build on this database to illustrate various concepts as we move along.
Let's start by creating one table, User, with the following columns:
| Name | Type | Nullable | Default | Other |
|---|---|---|---|---|
| userId | Int | No | PK / Identity | |
| username | Varchar(50) | No | ||
| password | Varchar(50) | No | ||
| firstName | Varchar(50) | No | ||
| lastName | Varchar(50) | No | ||
| dateCreated | DateTime | No | getDate() |
Note: Not all DBMS support default non-constant values. In this case simply set this column to not null. Later, when we generate objects we'll edit the Transfer Object (TO) and override the default value for this column.
Another Note: I use a convention where table names are singular. This is not required. You can call your table whatever you want. However, when objects are created the object type is appended to the table name to name the object.
So, if I create a Record Object based on the User table it will be named UserRecord. I think this is nicer on many levels than UsersRecord, which makes less sense, especially seeing as one record represents on row in the table.
Now that we've created this table why don't you manually throw a couple records in the table which we'll query for? I added the following record:
|
username |
dhughes |
|
password |
test |
|
firstName |
Doug |
|
lastName |
Hughes |