0% found this document useful (0 votes)
20 views3 pages

Employee and Student Database Operations

Uploaded by

ayushidixit248
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)
20 views3 pages

Employee and Student Database Operations

Uploaded by

ayushidixit248
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 PROGRAM LIST

1. Employee (name varchar(20), id int, age int, address varchar(30))


a. Create the database company.
b. Create the employee table and insert the 6 records in table.
c. How will you delete all records from the table
d. How will you find those employees who have maximum age.

2. Employee (name varchar(20), id int, age int, address varchar(30))


a. Create the database company.
b. Create the employee table and insert the 6 records in table.
c. Find the name of those employees whose name end with ‘L’.
d. Add salary column and find the average salary of employees .

3. Employee (name varchar(20), id int, age int, address varchar(30))


a. Create the database company.
b. Create the employee table and insert the 6 records in table.
c. Add a field name experience in employee table
d. Put the values in experience for every employee in the table.

4. Employee (name varchar(20), id int, age int, address varchar(30))


a. Create the database company.
b. Create the employee table and insert the 6 records in table.
c. Find the name of those employees who have ‘it’ as substring in name.
d. Find the minimum aged employee.

5. Employee (name varchar(20), id int, age int, address varchar(30))


a. Create the database company.
b. Create the employee table and insert the 6 records in table.
c. Make the default constraint with in the table.
d. Add a salary and find those employees who have salary between 20000 to
35000.

6. Student (name varchar(20), rollno int, age int, phy int, che int, bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. Find the name of those students who have passed in all subjects.
d. Find the name of those students who failed in all 3 subjects.

7. Customer (id int, name varchar(20), age int , address varchar(30))


a. Create the database shop.
b. Create the customer table and insert the 6 records in table.
c. Find all those customers whose name start with ‘S’ & end with ‘L’.
d. Make the age of customers in descending order.

8. Customer (id int, name varchar(20), age int, address varchar(30))


a. Create the database shop.
b. Create the customer table using check constraint and insert the 6 records in table.
c. How to make a primary key in the customer table.
d. Find the length of any name in customer table.

9. Customer (id int, name varchar(20), age int , address varchar(30))


a. Create the database shop.
b. Create the student table and insert the 5 records in table.
c. Use the default constraint in the name of customer.
d. Truncate the customer table.

10. Customer (id int, name varchar(20), age int, address varchar(30))
a. Create the database shop.
b. Create the customer table and insert the 6 records in table.
c. Make the table ascending order with age.
d. Find the customer name in upper case.

11. Student (name varchar(20), rollno int, age int, phy int, che int, bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. Select those students name whose age below 26 & living in ‘Agra’.
d. Create a view of the student table with age and roll no field.

12. Student (name varchar(20), rollno int, age int, phy int , che int , bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. How will you use rollback in deletion?
d. Count the number of students in the table?
13. Student (name varchar(20), rollno int, age int, phy int, che int , bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. Create an index on table student.
d. Delete a column in student table.

14. Student (name varchar(20), rollno int, age int, phy int, che int, bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. Add a primary key on column rollno with ALTER.
d. Update the age of any student in the given table.

15. Student (name varchar(20) , rollno int, age int, phy int, che int, bio int)
a. Create the database college.
b. Create the student table and insert the 6 records in table.
c. Delete those student record whose name start from ‘S’.
d. Select those student name whose age in between 25 and 35.

Common questions

Powered by AI

To identify records based on string patterns in names within SQL tables, you can use the `LIKE` operator, which allows pattern matching. For example, to find names ending with a specific letter, you would use `WHERE name LIKE '%L'`. Similarly, to find names containing a specific substring, you use `WHERE name LIKE '%it%'`. These methods enable efficient searching and can be complemented by using wildcards for more flexible matches .

To handle transactions and ensure data consistency when mistakenly deleting student records, use transaction control statements `BEGIN`, `ROLLBACK`, and `COMMIT`. Begin by initiating a transaction with `BEGIN;`, execute the delete operation, and if an error is detected or confirmation is needed, rollback the transaction with `ROLLBACK;` to undo changes. If the deletion is verified as correct, finalize with `COMMIT;` to make the changes permanent. This process ensures any accidental deletions can be reverted .

Constraints can maintain data integrity by restricting the range of acceptable values in a database field. For instance, to ensure birth dates are less than a certain year, use a `CHECK` constraint during table creation or alter an existing column. Use syntax such as `ALTER TABLE employee ADD CONSTRAINT check_birth_date CHECK (year(birth_date) < 1990);`. This constraint ensures all entered birth dates comply with the specified rule, preventing incorrect data input .

To ensure that an employee database contains only unique employee IDs, you would implement a primary key constraint on the ID column. This can be done by defining the ID column as a primary key during table creation or by altering the existing table structure with `ALTER TABLE employee ADD PRIMARY KEY (id);`. Using a primary key constraint is crucial for maintaining data integrity and preventing duplicate entries .

Implement an index on a student table to improve query performance leveraging the `CREATE INDEX` statement. For example, `CREATE INDEX idx_rollno ON student (rollno);`. To test the performance improvement, compare the execution time of queries before and after indexing using profiling tools or `EXPLAIN` commands. This method speeds up data retrieval specific to indexed columns, reducing search times and enhancing performance .

To add a new field to an existing database table and populate it for all records, you first alter the table to include the new column using the SQL statement `ALTER TABLE table_name ADD column_name datatype`. After adding the column, you can update the table to insert respective data for all records by using the `UPDATE` statement, setting the new column with desired values for each record. This ensures all existing entries have data in the newly introduced field .

Identify students who have failed all their subjects by querying the database to apply conditions on their exam scores. Use a SQL statement like `SELECT name FROM student WHERE phy < 40 AND che < 40 AND bio < 40;`, assuming passing marks are 40. This checks each subject's score for every student and retrieves names of those consistently below the passing threshold, indicating failure in all subjects .

To update selected fields of customer records based on certain conditions, use the SQL `UPDATE` statement with a `WHERE` clause to specify the conditions. For example, to update the age for all customers from a specific city, execute `UPDATE customer SET age = new_value WHERE address = 'specified_city';`. This selectively changes data in specified rows, maintaining existing data for non-matching rows .

To calculate the average salary of employees after adding a new salary column to the table, use the SQL `AVG()` function. First, add the salary column using `ALTER TABLE employee ADD COLUMN salary DECIMAL(10, 2);`, then populate it with data. Calculate the average by executing `SELECT AVG(salary) FROM employee;` to retrieve the average salary value across all records .

To ensure age values in a customer table are consistently sorted, use the SQL `ORDER BY` clause to sort the retrieved data. Execute a query such as `SELECT * FROM customer ORDER BY age ASC;` to organize all records in ascending order based on the age field. This sorting is temporarily applied to the results of the query and helps maintain consistency in reporting .

You might also like