What is the SQL to define DEFAULT
values in MySQL?
In the code below what needs to be added / changed to give IsObsolete a default value of N
?
CREATE TABLE Team ( TeamId CHAR(16) NOT NULL, DateCreated TIMESTAMP NOT NULL, IsObsolete CHAR(1) NOT NULL DEFAULT N, UpdateTime TIMESTAMP NOT NULL );
If a data type specification includes no explicit DEFAULT value, MySQL determines the default value as follows: If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause.
When using CREATE TABLE , you can specify default values for columns by typing DEFAULT and then the desired value after it. If a row is inserted that does not specify a value for that column, the database will fill it in with the default value instead.
IsObsolete CHAR(1) NOT NULL DEFAULT 'N'
You probably want to put quotes around it:
CREATE TABLE Team ( TeamId CHAR(16) NOT NULL, DateCreated TIMESTAMP NOT NULL, IsObsolete CHAR(1) NOT NULL DEFAULT 'N', UpdateTime TIMESTAMP NOT NULL );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With