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

SQL Practical File: Table Creation & Queries

Uploaded by

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

SQL Practical File: Table Creation & Queries

Uploaded by

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

SQL PRACTICAL FILE QUESTIONS

Q1.
A. Create a student table (ADMNO, CLASS-SEC, NAME, SCORE) and insert
data.
B. Implement the following SQL commands on the student table:
 ALTER table to add new attributes (SEX CHAR(1) / modify data type
CHAR to VARCHAR/ drop attribute SEX
 UPDATE table to modify data- Increase the marks of all students by 10
who scored less than 20.
 ORDER BY to display data in ascending / descending order by
(i)NAME wise (ii) SCORE wise
 DELETE to remove tuple(s) having SCORE less than 10.
 GROUP BY and find the min, max, sum, count and average
Q2.
A. Create a EMPLOYEE table (EID, NAME, SALARY, DEPT) and insert data.
B. Implement the following SQL commands on the student table:
 ALTER table to add new attributes – HRA INT(5) / modify data type of
HRA to decimal / drop attribute HRA
 UPDATE table to modify data – increase the salary by 10%
 ORDER BY to display data in ascending / descending order (i)SALARY
wise (ii) EID wise
 DELETE to remove tuple(s) – employee having emp id 101
 GROUP BY and find the min, max, sum, count and average.
Q3.
A. Create a Database LIBRARY.
B. Create a table BOOKs (book_id (PK), book_name, author_name,
publishers, price, type, qty) and Insert records
C. Create a table ISSUED(issue_id, book_id (FK), quantity_issued ) and
Insert records.
D. Write the SQL queries –
 To show Book name, Author name and Price of books of First Publ.
publishers. [SELECT, WHERE]
 To list the names from books of Text type. [SELECT, WHERE]
 To display the names and price from books in ascending order.
[ORDER BY]
 To increase the price of all books of EPB publishers by 50. [UPDATE]
 To display the Book_Id, Book_Name. and Quantity_Issued for all books
which have been issued. [JOIN QUERY]
 To display the list of books having publisher value is NULL.
 To display the unique name of all Publishers.
 To display the Maximum and Average Price of Books Publisher
 wise.
E. Write the Output of the following queries based on the above tables.
 SELECT COUNT(*) FROM BOOKS;
 SELECT MAX(PRICE) FROM BOOKS WHERE QUANTITY >= 15;
 SELECT BOOK_NAME, AUTHOR_NAME FROM BOOKS WHERE
PUBLISHERS = “EPB”;
 SELECT COUNT(DISTINCT PUBLISHERS) FROM BOOKS WHERE
PRICE >= 400;
Q4.
A. Create a Database COMPANY.
B. Create a table JOB (JOBID (PK), JOBTITLE, SALARY) and Insert Records.
C. Create a table Employee (EID (PK), NAME, SALES, JOBID (FK)) and
Insert Records
D. Write the SQL Queries for the following:
 To display employee ids, names of employees, job ids, with
corresponding job titles. (JOIN QUERY)
 To display names of employees, sales and corresponding job titles who
have achieved sales more than 130000. (JOIN QUERY)
 To display names and corresponding job titles of those employees who
have ‘SINGH’ (anywhere) in their names.
 Display the name of employee having maximum salary.
 Write the SQL command to change the JobId to 104 of the Employee
with ID as E4 in the table EMPLOYEE.
Q5.
A. Create a Table CLUB (CoachId, CoachName, Age, Sports, DateofApp, Pay,
Sex) and Insert Records.
B. Write the SQL Queries for the following: -
 To display the list of coach who is playing KARATE.
 To display the records having Pay between 500 to 1000.
 To display the names of coach whose name starts with ‘A’.
 To display the total salary paid to Coach Gender wise.
 To display all records alphabetically on name.
C. Give the output of following SQL statements: -
 SELECT COUNT(DISTINCT SPORTS) FROM CLUB;
 SELECT MIN(AGE) FROM CLUB WHERE SEX = ‘M’;
 SELECT AVG(AGE) FROM CLUB GROUP BY SEX;
 SLEECT SUM(PAY) FROM CLUB WHERE DATEOFAPP > ’31-03-1998’

Common questions

Powered by AI

Create SQL queries that specify IS NULL in WHERE clauses to target null fields, such as displaying books where the publisher value is NULL. This necessitates a strategic approach to data analysis to exclude or include missing data contextually.

Utilize JOIN queries to merge data from EMPLOYEE and JOB tables. For example, a query showing employees with sales over 130000 and their job titles requires combining these tables based on JOBID and applying a WHERE clause for the sales condition, thereby integrating table relationships for richer queries.

Sorting functions such as ORDER BY can arrange data in ascending or descending order based on specified columns like NAME or SCORE. The choice of criteria depends on the data analysis objective, such as alphabetizing names or ranking scores for readability or insights.

SQL uses functions like LIKE and wildcard characters to find patterns in text fields, useful when querying names containing substrings like 'SINGH'. This facilitates sophisticated textual data searches, aiding in refined databases filtering and pattern recognition within dataset text fields.

Use SELECT statements combined with WHERE clauses to filter results. For example, SELECT Book name, Author name, and Price from the BOOKS table where the publisher is 'First Publ.' or the book type is 'Text'. This precise filtering using conditions helps in extracting relevant dataset subsets.

The SQL commands include ALTER to add, modify, or drop attributes ('SEX' attribute), UPDATE to increase marks for specific conditions ('increase marks by 10 for students scoring less than 20'), ORDER BY to sort data ('by NAME or SCORE'), DELETE to remove entries ('where SCORE is less than 10'), and GROUP BY to compute aggregate functions ('min, max, sum, count, average')

First, use the ALTER command to modify the table structure, such as adding a new attribute or changing data types. Then, apply the UPDATE command to increase the salary by a specific percentage (10% in this case). This requires understanding the current data and its constraints to make the necessary adjustments accurately.

Apply an SQL UPDATE statement with a WHERE clause that specifies the unique identifier, such as an employee ID. For example, changing JobId for Employee E4 involves setting a new value where EID equals 'E4'. This precise targeting ensures that only the intended records are modified.

Use GROUP BY statements combined with aggregate functions (SUM, AVG) to compute summaries per group. For instance, to find the total salary based on gender, group data by 'Sex' in the table and sum 'Pay'. This organizing technique allows efficient extraction of aggregated financial insights.

Using GROUP BY with aggregate functions like MIN, MAX, SUM, COUNT, and AVG, one can derive detailed statistics categorized by groups, such as departments or publishers. This technique enables comprehensive data examination, uncovering trends and averages contextualized by specific attributes.

You might also like