Lab 05 Manual
Lab 05 Manual
Lab 05 Manual
Source: http://www.w3resource.com/mysql/creating-table-advance/constraint.php
Here in the above statement the constraint 'NOT NULL' have been used to
exclude the NULL VALUE.
The following picture shows that, the columns will not accept the NULL
values.
Lab Manual 05 (CONSTRAINTS)
Source: http://www.w3resource.com/mysql/creating-table-advance/constraint.php
Arguments
Name Description
REFERENCES Keyword.
primary key table Table name which contains the PRIMARY KEY.
column list A list of the columns on which PRIMARY KEY is set in the primary key table.
Example
If you want to do the following tasks :
A new table 'newbook_mast' will be created.
The PRIMARY KEY for that table 'newbook_mast' is 'book_id'.
The FOREIGN KEY for the table 'newbook_mast' is 'aut_id'.
The 'aut_id' is the PRIMARY KEY for the table 'newauthor'.
The FOREIGN KEY 'aut_id' for the table 'newbook_mast' points to the PRIMARY
KEY 'aut_id' of the table 'newauthor'.
That means the 'aut_id's which are present in the 'newauthor' table, only those
authors will come in the 'newbook_mast' table.
Here is the MySQL statement below for the above tasks.
3. invoice_dt date ,
4. ord_no varchar(25) ,
5. ord_date date ,
6. receive_dt date ,
7. book_id varchar(8) ,
8. book_name varchar(50) ,
9. pub_lang varchar(8) ,
10. cate_id varchar(8) ,
11. receive_qty int(5) ,
12. purch_price decimal(12,2) ,
13. total_cost decimal(12,2) ,
14. FOREIGN KEY(ord_no,book_id) REFERENCES
15. neworder(ord_no,book_id)
16. ON UPDATE CASCADE ON DELETE NO ACTION,
17. FOREIGN KEY(cate_id) REFERENCES category(cate_id));