MySQL 04 With Answers
MySQL 04 With Answers
INTEGRITY CONSTRAINTS
Type
CHAR (2)
VARCHAR (15)
VARCHAR (15)
DATE
Constraint
Primary Key
Not Null
Unique
Not null
2) List the columns and their associated constraints of the Members table.
desc people;
4) Insert the following 3 records shown below and save the changes. Display data.
ID
Name
User_id
DOB
M1
M2
M3
Azhar
Priya
Raj
A001
P001
R002
9) Delete the member M4. Save the changes. Display the data.
11) Modify Priyas name to Priyadarsini and User_id to P002. Verify using Select command.
12) Drop the unique constraint of User_id. Verify using describe command.
Name of Column
Job_id
Job_des
Salary
Type
INT (2)
VARCHAR (15)
FLOAT(8,2)
16) Add a new field named M_ID to the table Job. It should be of type Varchar and
size 4. Use the describe command to verify.
18) Insert a null value to Job_id and Secretary to job_des field to test the primary
key constraint.
20) Insert the value Officer two times using Insert command to test the unique key
constraint.
22) Insert a null value to job_des field to test not null constraint. Drop the not null
constraint.
23) Insert a tuple 10,clerk to job_id and job_des fields so that default value 3500 is
automatically added to Salary field. Display the data using select command.
24) Delete the record. Drop the default value of the field Salary.
25) Insert the following 3 records shown below and save the changes. Display data.
Job_id
Job_des
Salary
M_ID
10
11
12
Teacher
Cashier
Teacher
4000
3500
4000
M1
M2
M1
27) In both the tables i.e. ID of Members table and M_ID of Job table is same. Set
foreign key constraint for M_ID in job table with reference to ID of members table.
30) Create a new table Payment. Constraints to be added are Table level constraints.
Name of Column
Type
Constraint
Job_id
INT (2)
Des
VARCHAR (15)
Payment
FLOAT(8,2)
MID
Char(2)
Foreign key referencing Id of
members table.
31) Insert all records from job table to payment table. Test the foreign key constraint.
a) Delete the record from members table where ID is M1.
b) Modify the second record in members table by changing id M2 to M9.