Creating and Populating Tables

The CREATE statement is used to create a new table, and the INSERT statement is used to add a new record to a table.

The CREATE statement has this general format:

Format of SQL CREATE statement

Additional information

CREATE TABLE tablename(     colName dataType      <— can repeat this line, separated by commas optionalConstraint );

Here is an example of the use of the CREATE statement:

Example of SQL CREATE statement

Additional information

CREATE TABLE Person (        name      VARCHAR(100) PRIMARY KEY,   "PRIMARY KEYis a        age       INTEGER,                    constraint        lives_in  VARCHAR(100) );

This statement will create the Person table that we saw earlier ...

Get Just Java™ 2 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.