Google News
logo
HSQLDB - Interview Questions
How do you create a new table in HSQLDB?
To create a new table in HSQLDB, you can use SQL commands. Here's a basic example of how to create a new table:
CREATE TABLE <table_name> (
    column1 datatype1 [constraint],
    column2 datatype2 [constraint],
    ...
    [table_constraint]
);?

Replace <table_name> with the desired name for your new table. Define the columns of the table by specifying their names and data types. Optionally, you can add constraints to enforce data integrity rules on the table columns. Finally, you can include table-level constraints to enforce rules that involve multiple columns.

Here's a more concrete example :
CREATE TABLE Employee (
    employee_id INT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    email VARCHAR(100) UNIQUE,
    hire_date DATE,
    salary DECIMAL(10, 2),
    department_id INT,
    CONSTRAINT fk_department_id FOREIGN KEY (department_id) REFERENCES Department(department_id)
);?

In this example, we're creating a table named Employee with columns for employee ID, first name, last name, email, hire date, salary, and department ID. We've added primary and foreign key constraints to enforce data integrity rules.

Once you've executed the CREATE TABLE statement, the new table will be created in the database, and you can start inserting data into it, querying it, or performing other operations as needed.
Advertisement