Create a Table That Protects Its Data · practice
Create the Items Table
The five-column items design is still a description on the page. SQLite needs that description written as a SQL statement before it can build the table.
This is the complete statement we want:
CREATE TABLE items (
id INTEGER,
asset_tag TEXT,
name TEXT,
category TEXT,
loan_days INTEGER
);
CREATE TABLE items tells SQLite to make a table named items. Inside the parentheses, each line gives one column name followed by its declared type. Commas separate the column declarations, and ); finishes the statement.
Complete the table
Open schema.sql. It already contains the beginning of the statement:
CREATE TABLE items (
id INTEGER,
asset_tag TEXT
);
Add name TEXT, category TEXT, and loan_days INTEGER in that order. The finished file should match the complete five-column statement above.
Press Run when you are ready. SQLite will build a fresh, empty database from schema.sql. If it accepts the statement, the output begins with Schema loaded successfully. and shows the definition of items.
Read the printed definition once from top to bottom. It should name one table and show the same five columns you saw in the design, in the same order.
The commas are worth checking if SQLite reports an error. Every column line except the last one needs a comma after it. The last column is followed by the closing ); instead.
Press Submit after Run shows all five columns. The submission creates another empty database, checks the five-column design, and makes sure the table can hold one complete item. You do not need to add any rows yourself yet.
Each Run and Submit starts with a fresh in-memory database. That database disappears when the action finishes, but your schema.sql remains in the project. The file is the reusable instruction that can create the same table again whenever the lending program needs a new database.
You have turned a table design into SQL that SQLite can execute. The table has the right columns, but it does not yet protect their contents. For example, SQLite would currently accept two rows with the same id. That is the first rule you will add.
Task
Open schema.sql. Keep the existing id INTEGER and asset_tag TEXT columns. Then add name TEXT, category TEXT, and loan_days INTEGER in that order.
Add the commas needed to keep all five columns inside the same items table. Press Run and check that SQLite shows the complete table definition, then submit your work.