Professional Documents
Culture Documents
C3 WK02 DY03 PracticeExercise+ +questions
C3 WK02 DY03 PracticeExercise+ +questions
3. How many primary keys can be assigned to a table in SQL, and what is the
purpose of a primary key in a table? Give an example to illustrate this
concept?
10. What does "INDEX" do in SQL and how does it contribute to faster retrieval of
large databases?
11. What is the difference between "UNION" and "UNION ALL" in SQL?
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution
prohibited.
GLCA SQL Week2 Day 1 Practice Exercise
2. Create a foreign key constraint that references the "id" column of the
"employees" table on the "department" table's "employee_id" column.
4. Add a new column "email" to the "employees" table with the "not null"
constraint and a default value of "example@email.com".
5. Add not null constraints on the 'name' and 'email' columns in the 'employees'
table.
8. Create an enum column 'status' in the 'orders' table with allowed values
'pending', 'confirmed', and 'delivered'.
9. Add a default constraint on the 'status' column in the 'orders' table with the
value 'pending'.
10. Add a check constraint to ensure the 'age' column in the 'employees' table
has values greater than or equal to 18.
12. Create tables 'employees_a' and 'employees_b' with the following fields:
/*
employees_a:
- id
- name
- department
employees_b:
- id
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution
prohibited.
GLCA SQL Week2 Day 1 Practice Exercise
- name
- department
*/
-- insert values for the `employees_a` and `employees_b` with the following data
/*
employees_a : (1, 'John', 'Sales'), (2, 'Jane', 'Marketing'), (3, 'Jim', 'HR')
employees_b : (2, 'Jane', 'Marketing'), (4, 'Jack', 'IT')
*/
13. Write a SQL query to combine the data from 'employees_a' and 'employees_b'
using UNION operation and return the unique values in table 'employees_c'.
14. Write a SQL query to combine the data from 'employees_a' and 'employees_b'
using UNION ALL operation and return the unique values in table
'employees_d'.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution
prohibited.