Task

Create a table to store addresses.

You may assume that all the addresses to be stored will be located in the USA.   As such, you will need (in addition to a field holding a unique identifier) a field holding the street address, a field holding the city, a field holding the state code, and a field holding the zipcode.   Choose appropriate types for each field.

For non-database languages, show how you would open a connection to a database (your choice of which) and create an address table in it. You should follow the existing models here for how you would structure the table.




 
Import-Module -Name PSSQLite
 
 
## Create a database and a table
$dataSource = ".\Addresses.db"
$query = "CREATE TABLE SSADDRESS (Id        INTEGER  PRIMARY KEY  AUTOINCREMENT,
                                  LastName  TEXT     NOT NULL,
                                  FirstName TEXT     NOT NULL,
                                  Address   TEXT     NOT NULL,
                                  City      TEXT     NOT NULL,
                                  State     CHAR(2)  NOT NULL,
                                  Zip       CHAR(5)  NOT NULL
)"
 
Invoke-SqliteQuery -Query $Query -DataSource $DataSource
 
 
## Insert some data
$query = "INSERT INTO SSADDRESS ( FirstName,  LastName,  Address,  City,  State,  Zip)
                         VALUES (@FirstName, @LastName, @Address, @City, @State, @Zip)"
 
Invoke-SqliteQuery -DataSource $DataSource -Query $query -SqlParameters @{
        LastName  = "Monster"
        FirstName = "Cookie"
        Address   = "666 Sesame St"
        City      = "Holywood"
        State     = "CA"
        Zip       = "90013"
}
 
 
## View the data
Invoke-SqliteQuery -DataSource $DataSource -Query "SELECT * FROM SSADDRESS" | FormatTable -AutoSize
 