DBMS All Questions
DBMS All Questions
11 //////////////////////////////////////////////////////////////
The error message "Table 'q11.parts' doesn't exist" indicates that MySQL is unable
to find the parts table in the specified database (q11). This error occurs when the
table referenced in the trigger (parts) is not found in the database.
1 -->
DELIMITER //
DELIMITER ;
2 -->
DELIMITER //
-- Get the old price and quantity in hand for the given part number
SELECT price, qty_in_hands INTO old_price, qty_in_hand
FROM part
WHERE pno = p_part_number;
DELIMITER ;
///////////////////////////////////////////////////////////////////////// QUES 9
///////////////////////////////////////////////////////////////////////////////////
///////
********************************************
ALTER TABLE ChildTable
ADD CONSTRAINT FK_Name // FK_Name IS DIFFERENT FOR ALL
FOREIGN KEY (ChildColumn)
REFERENCES ParentTable(ParentColumn);
********************************************
CREATE TABLE Works (FORIEGN KEY e_id REFERENCE Employees(E_id), M_id int primary
key);
CREATE TABLE Departments (D_id int primary key , dep_name varchar(20), location_id
int);
CREATE TABLE Jobs(J_id int primary key , job_title varchar(20), min_salary int ,
max_salary int );
CREATE TABLE Locations (L_id int primary key , street varchar(20), state
varchar(20),country varchar(20));
CREATE TABLE Job_history (FORIGEN KEY E_id REFERENCE Employees(E_id) , PRIMARY KEY
(hire_date,leaving_date) , salary , FORIGEN KEY J_id REFERENCE Jobs(J_id) , FORIGEN
KEY D_id REFERENCE Departments(D_id) );
ERROR 1:- 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`q9`.`employees`, CONSTRAINT `fk1` FOREIGN KEY (`dep_id`) REFERENCES
`departments` (`D_id`))
SOLUTION :- For This Insert The Values In the Primary Key For Which We Written the
reference key the fill this table (INSERT IN FIRST IN THE TABLE WHERE NO FEFERNCE
KEY IS USED)
SOLUTION :-
The error message you received indicates that there is no index on the hire_date
column in the referenced table employees. In MySQL, when you define a foreign key
constraint, it requires an index on the referenced column(s) in the parent table to
optimize the lookup process.
To resolve this issue, you can create an index on the hire_date column in the
employees table, and then reattempt to add the foreign key constraint. Here's how
you can do it:
QUESTIONS :--->
PROCEDURE : -
DELIMITER //
DELIMITER ;
TRIGGER :-
DELIMITER //
DELIMITER ;
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////
The COALESCE function in SQL is used to return the first non-null expression in a
list. It takes multiple arguments and returns the first non-null value among them.
Here's how COALESCE works:
SELECT COALESCE(NULL, 1, 2, NULL, 3) AS result;
result
------
1
/////////////////////////////////////////
Q15 ////////////////////////////////////////
CREATE TABLE Employee (p_name varchar(50) primary key, street varchar(50), city
varchar(20));
1)
2)
3)
******************************************************************
SELECT e.person_name
FROM Employee e
JOIN Manages m ON e.person_name = m.person_name
JOIN Employee manager ON m.manager_name = manager.person_name
WHERE e.city = manager.city AND e.street = manager.street;
******************************************************************
////////////////////////////////////////////////////////////////////// QUES
4 //////////////////////////////////////////////////////////////////////////////
QUESTION 21
*********************** ERROR *****************************
The error you're encountering is due to the ONLY_FULL_GROUP_BY mode in MySQL, which
requires that all columns in the SELECT clause that are not part of an aggregate
function (such as COUNT, SUM, MAX, etc.) must also be included in the GROUP BY
clause. To resolve this error, you can modify your query to include D_NAME in the
GROUP BY clause:
sql
***************************************************************
************************************************
SOLUTION ------------------------------------------------>>>>>>>>>>>>>>>>>>>>>>
SELECT C.C_NAME
FROM CUSTOMER C
JOIN Orders O ON C.C_ID = O.C_ID
JOIN (
SELECT BILL_ID
FROM ORDER_DETAILS
ORDER BY TOTAL DESC
LIMIT 1
) OD ON O.BILL_ID = OD.BILL_ID;
LEAD() is a window function in SQL that allows you to access data from the next row
within the same result set. It is often used in conjunction with the ORDER BY
clause to define the order of rows. Here's an explanation of how LEAD() works:
--> WHILE CREATING THE TABLE YOU CREATE TABLE SUCH THAT WE CAN USE IT
EXAMPE:-
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE
);