CREATE, ALTER, and DROP table

The standard SQL statement for the table creation looks like this:

CREATE TABLE tablename (
  column1 type1,
  column2 type2,
  column3 type3,
  ....
);

The limitations for a table name, column names, and types of values that can be used depend on the particular database.  Here is an example of a command that creates table person in PostgreSQL:

CREATE TABLE person (
  id SERIAL PRIMARY KEY,
  first_name VARCHAR NOT NULL,  last_name VARCHAR NOT NULL,  dob DATE NOT NULL
);

As you can see, we have made the dob (date of birth) column not nullable. That imposes a constraint on our Person Java class that is going to represent the records of this table: its dob field cannot be null. And that was what we have done, you may recall, ...

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.