Fundamental Concepts Of Database Management Systems And SQL
Understand fundamental concepts of database management systems such data independence, data models, and database technologies.
This query is used to fetch the full names of an employee, the date that the employee was hired, and the title of the employee. Because the full names are saved as first name and last name the query uses an inbuilt sql function called concat which concatenates the two columns while adding a space between the two columns. To get the title a join between employees table and titles table is needed. The type of join used is inner join using the emp_no column in both tables thus the query returns all columns for which the emp_no in the employees table matches the emp_no in the titles table.
- SQL to show salaries and department name of all employees
This query is used to show the full names of each employee, their current salary and the department name the employee works in. Concat function is used to show the full names of the employee by concatenating the first name and the last name of the employee. The salary of an employee is found in the salaries table thus an inner join is done between the salaries table and the employee table using the emp_no column in both tables. To get the department name that an employee works in, a join between employees table and departments table is done using the joint table dept_emp.
- SQL to show full names and genders of HR department staff
This query is used to show the full names and the gender of all employees working in the human resources department. The first name and the last name are concatenated using the concat function. To join the employees and departments tables a join of the dept_emp supporting table is done. Finally a condition is used to filter only employees working in the human resources department.
- SQL to show all department name and their department managers
Results:
This query is used to show the names of all departments and the names of the manager for each respective department. To get the full names of the manager, concatenation of the first and last name of the manager is done using the concat function. An inner join between the departments table and dept_manager table is done and another inner join between the dept_manager and employees table is done. The dept_manager is the joint table joining departments and employees table.
- SQL to show department managers that were hired after 1986
This query Is used to get the department name, the name of the manager, the date that the manager was hired for all managers that were hired after 1986 which is from 1st of January 1987. To get the full names of the manager, concatenation of the first and last name of the manager is done using the concat function. An inner join between the departments table and dept_manager table is done and another inner join between the dept_manager and employees table is done. The dept_manager is the joint table joining departments and employees table.A condition is used to filter all managers who were hired after 1986.
- SQL to change an employee’s title using their lastname
Design and implement relational database systems.
This query is used to update the date of birth of an employee using their last name. The first query shows the details of the employees before the update is done. The second query updates only the date of birth of the employee with the last name as Simmels that is why according to the screenshot, only 1 row has been affected. The last query shows the details of the employee after the update query is done.
- SQL to delete an employee belonging to department d004 with id 10003
SQL Code:
This query is used to delete an employee with employee id 10003 who is working in department d004. The employee
- SQL to create view to list full names of all employees, their department managers and salaries
SQL Code:
Fetching the results of the query.
This view is created to get the full names of employees, their salaries and the full names of the department that the employee works in.
- SQL to create vies to list all departments and their department managers who were hired between 1980 and 1990.
SQL Code:
Select all the rows in the view
- SQL to increase salaries for all employees working in marketing department by 10%.
SQL Code:
Before Update:
Update Query
This query is used to update the salaries of all employees working in the marketing department. To update the salary you have to join the employees table to the supporting dept_emp table and then join it to the departments table and finally join it to the salaries table and restrict the update for only those employees working in the department with the department name marketing.
- Why database testing is important.
Database testing is important because complex applications require complex backend databases to support the application. Thus there is a need to test the database to make sure it meets the all requirements required for the efficient and accurate operation of the front end part of the application. Testing in databases is done for;
- Validation of the acid properties of the database.- This type of testing involves testing the Atomicity, Consistency, Isolation and durability of each database transaction. Atomicity is done to test whether a transaction passes or fails where it has to pass the all-or-nothing rule. Consistency involves testing whether each transaction will leave the database in a consistent state. Isolation property involves testing the database to make sure that if multiple transactions are executed at once then state of the database should be as if the transactions were executed in order. Finally durability involves testing that once a transaction is committed, no external factors can change its outcome.
- Data integrity- Testing to ensure data integrity involves making sure that for all tables that are related CRUD operations on each of the tables should maintain consistent data in all the tables. For example an update in the parent table should result to changes in the child tables.
- Testing process.
- Field size validation
Field size validation involves testing the database to make sure that the size of the field specified for a specific column is not violated. For example if a column has varchar data type and is restricted to a size of 50 then no data should have data exceeding 50 for this column.
To test field size validation we insert data in departments table where the dept_no should have is char(4) so we insert a record with more than 4 characters.
The query executes successfully but the value inserted in the table is trimmed to 4 characters as shown in the results below.
- Not null values
Not null validation ensures that a column that has a property of null must all always have a value during the insertion of a record. For example in the departments table the dept_name has not property thus inserting a null value would fail.
Query
When this query is executed it fails because dept_name should not have a null value.
- Primary key
Primary key validation involves making sure no duplicate primary keys exist in a table because every primary key is supposed to be unique. For example in the departments table, inserting a duplicate entry key results to an error as shown in below.
- Foreign key
Foreign key validation involves testing that no integrity constraints are violated. For example you cannot insert a record in the child table for a primary key that does not exist in the parent table. For example considering two tables; employees the parent table and salaries the child table, you cannot insert a salary record for an employee that does not exist as demonstrated in the screenshot below.
References
Sharma, R., Mohamed, A., Aryan, M., kuchana, r., Ramesh, M. and patra, s. (2018). Database Testing Guide (Why, How, and What About Database Testing). [online] Softwaretestinghelp.com. Available at: https://www.softwaretestinghelp.com/database-testing-process/ [Accessed 20 Nov. 2018].