sql / beginner
Snippet
Requiring Column Values via NOT NULL Constraints
The NOT NULL constraint prevents a column from accepting NULL values. This ensures that essential attributes, such as product names or prices, are mandatory upon record creation.
snippet.sql
sql
1
2
3
4
5
CREATE TABLE products (product_id INTEGER PRIMARY KEY,product_name VARCHAR(100) NOT NULL,price DECIMAL(10, 2) NOT NULL);
Breakdown
1
CREATE TABLE products (
Starts creating a new table named 'products'.
2
product_id INTEGER PRIMARY KEY,
Declares 'product_id' as an integer and the table's primary identifier.
3
product_name VARCHAR(100) NOT NULL,
Defines a text column that cannot be left empty (NULL).
4
price DECIMAL(10, 2) NOT NULL
Defines a precise numeric column for currency that strictly requires a value.
5
);
Concludes the table structure creation.