Example If you want to create a table 'newauthor' where no columns are allowed to store NULL VALUES the following statement can be used.
The column level constraints can apply only to one column where as table level constraints are applied to the entire table.
My SQL CONSTRAINT is declared at the time of creating a table.
The picture below shows the structure of the table.
Example of My SQL UNIQUE CONSTRAINT check unique value The My SQL statement stated below will create a table 'newauthor' with a column 'aut_id' which is meant to store unique values only.
My SQL CONSTRAINTS are used to limit the type of data that can be inserted into a table.
My SQL CONSTRAINTS can be classified into two types - column level and table level.Example The My SQL statement stated below will create a table 'newpublisher' with a PRIMARY KEY on 'pub_id' column, a CHECK constraint with logical operators for country and pub-city columns and a default value for pub_id, pub_name, pub_city and country columns.The My SQL statement also sets the default value white space for pub_id, pub_name, pub_city columns and 'India' as a default value for a country column. CREATE TABLE IF NOT EXISTS newpublisher (pub_id varchar(8) NOT NULL UNIQUE DEFAULT '' , pub_name varchar(50) NOT NULL DEFAULT '' , pub_city varchar(25) NOT NULL DEFAULT '' , country varchar(25) NOT NULL DEFAULT 'India', country_office varchar(25) , no_of_branch int(3), estd date CHECK ((country='India' AND pub_city='Mumbai') OR (country='India' AND pub_city='New Delhi')) , PRIMARY KEY (pub_id)); My SQL CREATE TABLE with AUTO INCREMENT My SQL allows you to set AUTO_INCREMENT to a column.My SQL CREATE TABLE with NULL CONSTRAINT Using the default value as NOT NULL, while creating a My SQL table, it can be enforced that a column in a table is not allowed to store NULL values.If you want to create a table 'newauthor' where no columns are allowed to store NULL VALUES the following statement can be used.The following picture shows that the columns will not accept the NULL values.