3.PracticalSQL2E SampleCh3
3.PracticalSQL2E SampleCh3
Note that the id column (of type bigserial) is automatically filled with
sequential integers, even though you didn’t explicitly insert them. Very
handy. This auto-incrementing integer acts as a unique identifier, or key,
that not only ensures each row in the table is unique, but also later gives us
a way to connect this table to other tables in the database.
Before we move on, note that you have two other ways to view all rows
in a table. Using pgAdmin, you can right-click the teachers table in the
object tree and choose View/Edit DataAll Rows. Or you can use a little-
known bit of standard SQL:
TABLE teachers;
Both provide the same result as the code in Listing 3-1. Now, let’s refine
this query to make it more specific.
With that syntax, the query will retrieve all rows from just those three
columns.
Let’s apply this to the teachers table. Perhaps in your analysis you want
to focus on teachers’ names and salaries, not the school where they work
or when they were hired. In that case, you would select just the relevant
columns. Enter the statement shown in Listing 3-2. Notice that the order of
the columns in the query is different than the order in the table: you’re able
to retrieve columns in any order you’d like.
Although these examples are basic, they illustrate a good strategy for
beginning your interview of a dataset. Generally, it’s wise to start your
analysis by checking whether your data is present and in the format you