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

5 - 2

The document outlines the creation of a database named 'experiment_5' with tables for 'owner' and 'dog', including their relationships. It includes SQL commands for inserting data, selecting specific records, creating a trigger to limit dog ownership, and defining a stored procedure to list dogs by purchase date. Additionally, it shows MongoDB commands for creating a collection, inserting, updating, and deleting dog records based on gender.

Uploaded by

Venkatesh O
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)
7 views2 pages

5 - 2

The document outlines the creation of a database named 'experiment_5' with tables for 'owner' and 'dog', including their relationships. It includes SQL commands for inserting data, selecting specific records, creating a trigger to limit dog ownership, and defining a stored procedure to list dogs by purchase date. Additionally, it shows MongoDB commands for creating a collection, inserting, updating, and deleting dog records based on gender.

Uploaded by

Venkatesh O
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
You are on page 1/ 2

5 QUESTION

b.
CREATE DATABASE experiment_5;
CONNECT experiment_5;
CREATE TABLE owner (
ssn INT PRIMARY KEY,
name VARCHAR(20),
address VARCHAR(20)
);
CREATE TABLE dog (
ssn INT,
name VARCHAR(20),
gender CHAR(1),
dop DATE,
PRIMARY KEY (ssn, name),
FOREIGN KEY (ssn) REFERENCES owner(ssn)
);
INSERT INTO owner VALUES
(101, 'Owner One', '123 Elm St'),
(102, 'Owner Two', '456 Oak St'),
(103, 'Owner Three', '789 Pine St');
INSERT INTO dog VALUES
(101, 'Dog One', 'M', '2022-01-10'),
(101, 'Dog Two', 'F', '2023-03-25'),
(102, 'Dog Three', 'M', '2024-07-15');
c.
SELECT D.name, D.gender, D.dop
FROM dog D, owner O
WHERE O.name = 'Abhiman'
AND D.ssn = O.ssn;
d.
SELECT O.name
FROM owner O
WHERE NOT EXISTS
(
SELECT *
FROM dog D
WHERE O.ssn = D.ssn
);
e.
DELIMITER //
CREATE TRIGGER tr5
BEFORE INSERT ON dog
FOR EACH ROW
BEGIN
DECLARE cnt INT;
SELECT COUNT(*) INTO cnt FROM dog
WHERE ssn = NEW.ssn;
IF cnt >= 3 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'A person can own a maximum of three pet dogs';
END IF;
END //
DELIMITER ;
f.
DELIMITER //
CREATE PROCEDURE list_dogs(IN pur_date DATE)
BEGIN
SELECT O.name, O.ssn, O.address, D.name, D.ssn, D.gender
FROM owner O, dog D
WHERE O.ssn = D.ssn AND D.dop = pur_date;
END //
DELIMITER ;
g.
use experiment_5;
db.createCollection('dog');
db.dog.insertOne({
name: "Buddy",
gender: "Male"
});
db.dog.insertMany([
{
name: "Bella",
gender: "Female"
},
{
name: "Max",
gender: "Male"
}
]);
db.dog.updateOne(
{ name: "xyz" },
{ $set: { name: "abc" } }
);
db.dog.deleteMany({ gender: "Male" });
db.dog.find({ gender: "Female" });

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy