apache derby create table
To create a table in Apache Derby, you can use the CREATE TABLE
statement. Here is the basic syntax:
CREATE TABLE table_name ( column1 datatype [constraint], column2 datatype [constraint], ... );
Here is an example of creating a simple table in Apache Derby:
CREATE TABLE students ( id INT NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, age INT, email VARCHAR(100) UNIQUE );
In this example, we are creating a table called students
with four columns: id
, name
, age
, and email
. The id
column is defined as an integer data type with a NOT NULL
constraint and a PRIMARY KEY
constraint, which ensures that each row in the table has a unique value for the id
column. The name
column is defined as a variable-length character data type (VARCHAR
) with a maximum length of 50 characters and a NOT NULL
constraint, which ensures that each row has a value for the name
column. The age
column is defined as an integer data type with no constraints, which means that it can have null values. The email
column is defined as a variable-length character data type (VARCHAR
) with a maximum length of 100 characters and a UNIQUE
constraint, which ensures that each value in the email
column is unique across all rows in the table.
You can customize the column definitions based on your specific needs and requirements. You can also add additional constraints, such as CHECK
constraints, FOREIGN KEY
constraints, or DEFAULT
values, to further enforce data integrity and consistency in your table.