0% found this document useful (0 votes)
11 views2 pages

MySQL Practical File Queries Guide

The document contains 25 queries to be completed in MySQL. It involves creating databases and tables, inserting records, displaying data, modifying structures and data, joining tables, filtering on conditions, sorting, grouping, and updating records.

Uploaded by

aman yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

MySQL Practical File Queries Guide

The document contains 25 queries to be completed in MySQL. It involves creating databases and tables, inserting records, displaying data, modifying structures and data, joining tables, filtering on conditions, sorting, grouping, and updating records.

Uploaded by

aman yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical File Questions

Complete these 25 given queries in Mysql, paste the query and result in MSWord document.

Q1. Create a database say School in mysql?

Q2. How to go to a particular database say school?

3. Create a table Dept having fields Deptno as int type, Dname as varchar type and Loc
Varchar type. Consider Deptno as primary key.

4. Insert record in Dept table

5. Create a table Employ having following details:

Table name: Employee

Field Name Data type Length Constraint

Eno Integer Primary key

Ename Varchar 15 Not Null

Gender Char 1

Doj Date

Salary Decimal 10,2

Deptno int Foreign key

Q6. Display structure of the table Employee

Q7. Insert 5 records in Employee table


8. Display all the records in employee table

9. Display Eno, Ename from employee table only for Gents Employee

10. Display those ename whose salary between 40000 to 60000 both inclusive.

11. Display those record whose name starts with A

12. Display those Ename whose name 3rd char is r.

13. Display all the records in ascending order of Ename

14. Display those records in Descending order of Fees

15. Add a column City in table Employee

16. Delete column City.

17. Display Gender wise Number of employees

18. Display all the records whose salary is Null

19. Make Deptno as Foreign key

20. Display all the records of dept table

21. Display Eno, Ename, Salary, Deptno, Dname

22. Display Eno, Ename, Salary, Deptno, dname for those employee who gets salary more
than 50000.

23. Display those employees who joined after 01.01.2011

24. Delete those records who earn 0(zero)

25. Increase salary of all employee by 30%

Common questions

Powered by AI

Increasing salaries by a fixed percentage uniformly, like the 30% mentioned, can be executed via a query like `UPDATE Employee SET Salary = Salary * 1.3`. The benefits include streamlined adjustment across the board, supporting company-wide incentives. However, it may lack consideration for performance-based differentiation, possibly leading to fairness issues or budgetary constraints if not strategically planned .

The query `SELECT Gender, COUNT(*) FROM Employee GROUP BY Gender` displays employee counts per gender. This application aids diversity survey analytics, helping assess representation balance, identify gaps, and drive inclusion strategies. It's foundational in action plans promoting equitable workplace environments and informed HR policies .

Displaying salary ranges, executed by a query like `SELECT Ename FROM Employee WHERE Salary BETWEEN 40000 AND 60000`, enhances transparency, building trust when clear compensation information is accessible. It improves employee satisfaction as it aligns with fairness perceptions. However, it may lead to dissatisfaction if disparities are noticeable without justified context or adaptation incentives .

Sorting employee records in ascending order, such as by `ORDER BY Ename ASC`, facilitates alphabetical listing helpful for structured databases, enabling easy retrieval and comparison. Descending order, achieved via `ORDER BY Ename DESC`, can prioritize seeing the most recent additions or highest values first, useful in hierarchical or priority-based evaluations. Each method serves different analytical or operational needs, like optimizing viewing relevance or auditor reviewing .

To add a new column, such as 'City', to the 'Employee' table, use the SQL command `ALTER TABLE Employee ADD COLUMN City VARCHAR(255)`. To remove the same column later, use `ALTER TABLE Employee DROP COLUMN City`. These commands allow dynamic modification of table structure by accurately using 'ALTER TABLE' statements .

To ensure referential integrity in MySQL, you need to define the foreign key constraint properly. When creating the 'Employee' table, the 'Deptno' column is defined as a foreign key that references the 'Deptno' column in the 'Dept' table. This can be achieved using the following SQL syntax: `CREATE TABLE Employee (Deptno INT, FOREIGN KEY (Deptno) REFERENCES Dept(Deptno))`. This ensures that any value of 'Deptno' in the 'Employee' table must correspond to a valid 'Deptno' in the 'Dept' table, thereby maintaining referential integrity .

Displaying records with a NULL salary might indicate cases where employee compensation details are incomplete or pending finalization. It can suggest data entry errors or temporary placeholders before salary assignment. Handling these NULL values is crucial for accurate reporting and analytics as they can lead to incorrect aggregation results. Corrective actions might involve data validation during entry or periodic audits to ensure data integrity .

Updating a foreign key involves initially verifying the referenced table's primary key constraints. In the 'Employee' table, if 'Deptno' should reference 'Dept', use `ALTER TABLE Employee ADD CONSTRAINT FK_Dept FOREIGN KEY (Deptno) REFERENCES Dept(Deptno)`. Maintain this through routine integrity checks and updates matching data from both tables, imperative for consistent relational integrity, preventing orphaned records, and ensuring coherent data linkages .

To display employees who joined after a specific date, such as 01.01.2011, you use the query `SELECT * FROM Employee WHERE Doj > '2011-01-01'`. This query is useful for HR analytics as it helps identify recent hires, enabling analysis of recruitment trends, staff retention, and workforce demographics over time .

Using `SELECT Ename FROM Employee WHERE Ename LIKE 'A%'` efficiently retrieves employee names starting with 'A'. This method isolates groups based on name characteristics, useful for tailored communications, organizational division, or cultural analysis efforts. In large datasets, such queries simplify targeted reporting or departmental distribution .

You might also like