SQL WITH DOMAIN CONSTRAINTS(check constraints)

MySQL CREATE TABLE with CHECK CONSTRAINT using IN operator
MySQL CHECK CONSTRAINT can be applied to a column of a table, to set a limit for storing values within a range, along with IN operator.
Example
If you want to create a table 'newauthor' with a PRIMARY KEY on a combination of two columns (aut_id,home_city) and checking a limit value for the column country are 'USA','UK' and 'India', the following statement can be used.
CREATE TABLE IF NOT EXISTS
newauthor(aut_id varchar(8) NOT NULL , 
aut_name varchar(50) NOT NULL,
country varchar(25) NOT NULL CHECK (country IN ('USA','UK','India')), 
home_city varchar(25) NOT NULL, 
PRIMARY KEY (aut_id,home_city));


Resource:https://www.w3resource.com/mysql/creating-table-advance/constraint.php

Comments

Popular posts from this blog

Lab Network 2024

Step to publish your static html web page to GitHub

Tutorial OOP(reversion java)