0
0
MySQLquery~10 mins

Primary key declaration in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a primary key on the 'id' column.

MySQL
CREATE TABLE users (id INT [1], name VARCHAR(100));
Drag options to blanks, or click blank then click option'
AINDEX
BFOREIGN KEY
CUNIQUE
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY instead of PRIMARY KEY
Using UNIQUE without PRIMARY KEY
Forgetting to specify any key constraint
2fill in blank
medium

Complete the code to declare a primary key on the 'order_id' column in this table.

MySQL
CREATE TABLE orders (order_id INT [1], order_date DATE);
Drag options to blanks, or click blank then click option'
AUNIQUE
BPRIMARY KEY
CCHECK
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of PRIMARY KEY
Using CHECK constraint incorrectly
Not specifying any key constraint
3fill in blank
hard

Fix the error in this table creation by correctly declaring the primary key.

MySQL
CREATE TABLE products (product_id INT, name VARCHAR(50), [1] (product_id));
Drag options to blanks, or click blank then click option'
APRIMARY KEY
BFOREIGN KEY
CUNIQUE
DCHECK
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY instead of PRIMARY KEY
Using UNIQUE constraint without PRIMARY KEY
Using CHECK constraint incorrectly
4fill in blank
hard

Fill both blanks to declare a composite primary key on 'student_id' and 'course_id'.

MySQL
CREATE TABLE enrollments (student_id INT, course_id INT, [1] (student_id, [2]));
Drag options to blanks, or click blank then click option'
APRIMARY KEY
Bcourse_id
CFOREIGN KEY
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY instead of PRIMARY KEY
Listing only one column in the key
Using UNIQUE instead of PRIMARY KEY
5fill in blank
hard

Fill all three blanks to declare a primary key on 'id' and add a unique constraint on 'email'.

MySQL
CREATE TABLE users (id INT [1], email VARCHAR(100) [2], [3] (email));
Drag options to blanks, or click blank then click option'
APRIMARY KEY
BUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing PRIMARY KEY and UNIQUE keywords incorrectly
Forgetting to declare unique constraint on email
Using FOREIGN KEY instead of UNIQUE