Creating a Table with Default Values in SQL
To create a table 'tInventoryPlan2' with default values for fields, you can use the following SQL query:
CREATE TABLE tInventoryPlan2 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(50) DEFAULT 'Unknown',
quantity INT DEFAULT 0,
price DECIMAL(10, 2) DEFAULT 0.00
);
In this example, the 'product_name' field has a default value of 'Unknown', the 'quantity' field has a default value of 0, and the 'price' field has a default value of 0.00. These values will be used if no value is specified for these fields during an 'INSERT' operation. The 'id' field is set to 'NOT NULL' and 'AUTO_INCREMENT' to ensure each record has a unique identifier.
原文地址: https://www.cveoy.top/t/topic/ogHn 著作权归作者所有。请勿转载和采集!