
Now, let us create a table named tblPatient with NOT NULL constraint. A foreign key constraint prevents the UPDATE and DELETE statement that breaks the link between two tables.
A table can have one or more foreign keys. The foreign key of any table refers to the Primary Key of another table.
FOREIGN KEY: The foreign key is a column that creates a link between two tables. When we create a primary key, a clustered index will be created automatically. We can create one primary key in a table. The primary key contains unique values and cannot contain a NULL value. The primary key consists of one or more columns. Following are the characteristics of the Primary key PRIMARY KEY: The Primary key constraint is used to identify each record uniquely. If we do not specify the values for the column on which the default constraint, it inserts the default value specified in the DEFAULT constraints. DEFAULT: The DEFAULT constraint inserts a default value. The syntax is the same for Oracle, SQL Server, MySQL, and PostgreSQL. CHECK: When we insert a record in a table, the check constraint ensures that the values that we are inserting in a column must satisfy the condition specified in a CHECK constraint. This example uses the Create Table as Select to create a table from another table, but no data is added to the new table. UNIQUE: This constraint ensures that the query inserts only unique values in the column on which the constraint has been created. NOT NULL: This constraint ensures that a query does not insert a NULL value in a column on which the constraint has been created. A table can have the following constraints. MYSQL CREATE TABLE IN DATABASE HOW TO
Now, let us understand how we can create a table with a constraint. How to create a table in a particular database Ask Question Asked 13 years, 1 month ago Modified 5 years, 5 months ago Viewed 111k times 48 The create database statement is: CREATE TABLE tablename ( columnname1 datatype, columnname2 datatype, columnname3 datatype. The above command creates a table named tblPatient in Patients schema.