A Bit About Database Keys, Part 2: Primary and Foreign Keys

In Part 1 of this series about database keys, we looked at the difference between natural and surrogate keys, using a table with data about friends.  Here’s that table again:

SELECT * FROM friends;
 first_name | last_name | hair_color | id 
------------+-----------+------------+----
 Monica     | Geller    |            |  1
 Ross       | Geller    |            |  2
 Chandler   | Bing      |            |  3
 Joey       | Tribbiani |            |  4
 Rachel     | Green     |            |  5
 Phoebe     | Buffet    | blonde     |  6
 Monica     | Lewinsky  |            |  7
 Al         | Green     |            |  8
 Joey       | Kangaroo  | orange     |  9
(9 rows)

The table contains columns for data about first name, last name, and hair color, plus an  id column that was created to uniquely identify each row, regardless of whether or not the values in the other columns were unique.

Primary Keys

The  id column of the  friends table is an example of a primary key.  A primary key is used to uniquely identify a row in the same table.  Columns can be explicitly specified as primary keys in PostgreSQL using  PRIMARY KEY , as was done when the column was created in the previous article:

ALTER TABLE friends
ADD COLUMN id serial PRIMARY KEY;

A primary key is usually, though not always, an automatically-incrementing integer.  But no matter the data type, a primary key must be unique, and so surrogate keys make great primary keys.

Read more

A Bit About Database Keys, Part 1: Natural vs. Surrogate Keys

Keys are values that uniquely identify a single row in a database table.  They are necessary because it is highly possible that a table will have two rows that contain identical data but represent two separate entities in the real world.

Let’s say we wanted to create a table in PostgreSQL to store information about our friends.  The schema for this table might be created with the following code:

CREATE TABLE friends(
first_name text,
last_name text
);

This table has two text columns, one for first name and one for last name.  Now let’s populate our table with some data:

Read more

Increasing Text Color Contrast Improves Readability

Recently, I helped a friend with her website.  I had just spent the whole day staring at a computer screen, and my eyes were tired. So the first thing I noticed was the contrast between the body text and the background…or rather, the lack thereof.

The page looked something like this:

An example of low contrast text.
This text isn’t very easy to read, especially if you have a vision impairment.

I have made many similar color decisions myself in the past.  When I first started making websites, choosing the colors was my favorite part. The only criterion I used to decide colors for text and background was, “does it look pretty?”

What I didn’t realize at that point was that color choice can make a website difficult to read, and even exclude users from being able to view a website at all.

Web Content Accessibility Guidelines (WCAG)

The Web Accessibility Initiative (WAI) of the World Wide Web Consortium (W3C)  has published a set of standards for web content, called the the Web Content Accessibility Guidelines (WCAG for short). Within this document are standards for just about every aspect of web content, including colors, images, video, text, and documents.

Read more