0% found this document useful (0 votes)
31 views12 pages

MSQL Database

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

MSQL Database

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

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 22
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database vbj;


Query OK, 1 row affected (0.01 sec)

mysql> use vbj;


Database changed
mysql> CREATE TABLE Properties (
-> id INT AUTO_INCREMENT,
-> address VARCHAR(255) NOT NULL,
-> type VARCHAR(255) NOT NULL,
-> size DECIMAL(10, 2) NOT NULL,
-> price DECIMAL(10, 2) NOT NULL,
-> status VARCHAR(255) NOT NULL,
-> owner_agent_id INT,
-> PRIMARY KEY (id),
-> FOREIGN KEY (owner_agent_id) REFERENCES Agents(id));
ERROR 1824 (HY000): Failed to open the referenced table 'agents'
mysql> CREATE TABLE Agents (
-> id INT AUTO_INCREMENT,
-> name VARCHAR(255) NOT NULL,
-> contact_info VARCHAR(255) NOT NULL,
-> email VARCHAR(255) NOT NULL,
-> PRIMARY KEY (id)
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
' KEY (id)
)' at line 6
mysql> CREATE TABLE Agents (
-> id INT AUTO_INCREMENT,
-> name VARCHAR(255) NOT NULL,
-> contact_info VARCHAR(255) NOT NULL,
-> email VARCHAR(255) NOT NULL,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE Clients (


-> id INT AUTO_INCREMENT,
-> name VARCHAR(255) NOT NULL,
-> contact_info VARCHAR(255) NOT NULL,
-> email VARCHAR(255) NOT NULL,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE Properties (


-> id INT AUTO_INCREMENT,
-> address VARCHAR(255) NOT NULL,
-> type VARCHAR(255) NOT NULL,
-> size DECIMAL(10, 2) NOT NULL,
-> price DECIMAL(10, 2) NOT NULL,
-> status VARCHAR(255) NOT NULL,
-> owner_agent_id INT,
-> PRIMARY KEY
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')' at
line 10
mysql> CREATE TABLE Properties (
-> id INT AUTO_INCREMENT,
-> address VARCHAR(255) NOT NULL,
-> type VARCHAR(255) NOT NULL,
-> size DECIMAL(10, 2) NOT NULL,
-> price DECIMAL(10, 2) NOT NULL,
-> status VARCHAR(255) NOT NULL,
-> owner_agent_id INT,
-> PRIMARY KEY (id),
-> FOREIGN KEY (owner_agent_id) REFERENCES Agents(id)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE TABLE Transactions (


-> id INT AUTO_INCREMENT,
-> property_id INT NOT NULL,
-> client_id INT NOT NULL,
-> agent_id INT NOT NULL,
-> sale_price DECIMAL(10, 2) NOT NULL,
-> date DATE NOT NULL,
-> PRIMARY KEY (id),
-> FOREIGN KEY (property_id) REFERENCES Properties(id),
-> FOREIGN KEY (client_id) REFERENCES Clients(id),
-> FOREIGN KEY (agent_id) REFERENCES Agents(id)
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> CREATE TABLE Client_Interests (


-> client_id INT NOT NULL,
-> property_id INT NOT NULL,
-> PRIMARY KEY (client_id, property_id),
-> FOREIGN KEY (client_id) REFERENCES Clients(id),
-> FOREIGN KEY (property_id) REFERENCES Properties(id)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE TABLE Agent_Managed_Properties (


-> agent_id INT NOT NULL,
-> property_id INT NOT NULL,
-> PRIMARY KEY (agent_id, property_id),
-> FOREIGN KEY (agent_id) REFERENCES Agents(id),
-> FOREIGN KEY (property_id) REFERENCES Properties(id)
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO Properties (address, type, size, price, status, owner_agent_id)
-> VALUES ('123 Main St', 'Residential', 2000.00, 500000.00, 'For Sale', 1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
' 'For Sale', 1)' at line 2
mysql> INSERT INTO Properties (address, type, size, price, status, owner_agent_id)
-> VALUES
-> ('456 Elm St', 'Commercial', 3500.00, 850000.00, 'For Sale', 2),
-> ('789 Oak St', 'Residential', 1500.00, 300000.00, 'Sold', 1),
-> ('321 Pine St', 'Residential', 2500.00, 600000.00, 'For Rent', 3),
-> ('654 Maple Ave', 'Commercial', 4000.00, 950000.00, 'For Sale', 2),
-> ('987 Cedar Blvd', 'Residential', 1800.00, 450000.00, 'Under Contract',
1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`properties`, CONSTRAINT `properties_ibfk_1` FOREIGN KEY
(`owner_agent_id`) REFERENCES `agents` (`id`))
mysql> SELECT * FROM Agents;
Empty set (0.00 sec)

mysql> INSERT INTO Agents (name, contact_info, email)


-> VALUES
-> ('John Doe', '123-456-7890', '[email protected]'),
-> ('Jane Smith', '987-654-3210', '[email protected]'),
-> ('Alice Johnson', '555-123-4567', '[email protected]');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM Agents;


+----+---------------+--------------+-------------------+
| id | name | contact_info | email |
+----+---------------+--------------+-------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
| 2 | Jane Smith | 987-654-3210 | [email protected] |
| 3 | Alice Johnson | 555-123-4567 | [email protected] |
+----+---------------+--------------+-------------------+
3 rows in set (0.00 sec)

mysql> INSERT INTO Clients (name, contact_info, email)


-> VALUES
-> ('Michael Brown', '111-222-3333', '[email protected]'),
-> ('Emily Davis', '444-555-6666', '[email protected]'),
-> ('David Wilson', '777-888-9999', '[email protected]'),
-> ('Sarah Miller', '123-123-1234', '[email protected]'),
-> ('James Taylor', '555-555-5555', '[email protected]');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Agents (name, contact_info, email)


-> VALUES
-> ('John Doe', '123-456-7890', '[email protected]'),
-> ('Alice Johnson', '555-123-4567', '[email protected]'),
-> ('Michael Brown', '111-222-3333', '[email protected]'),
-> ('Emily Davis', '444-555-6666', '[email protected]');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,


date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES
-> (2, 1, 1, 300000.00, '2022-02-01'),
-> (1, 2, 2, 450000.00, '2022-03-01'),
-> (3, 3, 1, 600000.00, '2022-04-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' '2022-
01-01')' at line 2
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> SELECT * FROM Properties;
Empty set (0.00 sec)

mysql> INSERT INTO Properties (address, type, size, price, status, owner_agent_id)
-> VALUES
-> ('123 Main St', 'Residential', 2000.00, 500000.00, 'For Sale', 1),
-> ('456 Elm St', 'Commercial', 3500.00, 850000.00, 'For Sale', 2),
-> ('789 Oak St', 'Residential', 1500.00, 300000.00, 'Sold', 1),
-> ('321 Pine St', 'Residential', 2500.00, 600000.00, 'For Rent', 3),
-> ('654 Maple Ave', 'Commercial', 4000.00, 950000.00, 'For Sale', 2);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql>
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES
-> (2, 1, 1, 300000.00, '2022-02-01'),
-> (1, 2, 2, 450000.00, '2022-03-01'),
-> (3, 3, 1, 600000.00, '2022-04-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql>
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> SELECT * FROM Properties;
+----+---------------+-------------+---------+-----------+----------
+----------------+
| id | address | type | size | price | status |
owner_agent_id |
+----+---------------+-------------+---------+-----------+----------
+----------------+
| 6 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
| 7 | 456 Elm St | Commercial | 3500.00 | 850000.00 | For Sale |
2 |
| 8 | 789 Oak St | Residential | 1500.00 | 300000.00 | Sold |
1 |
| 9 | 321 Pine St | Residential | 2500.00 | 600000.00 | For Rent |
3 |
| 10 | 654 Maple Ave | Commercial | 4000.00 | 950000.00 | For Sale |
2 |
+----+---------------+-------------+---------+-----------+----------
+----------------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM Clients;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
| 2 | Emily Davis | 444-555-6666 | [email protected] |
| 3 | David Wilson | 777-888-9999 | [email protected] |
| 4 | Sarah Miller | 123-123-1234 | [email protected] |
| 5 | James Taylor | 555-555-5555 | [email protected] |
+----+---------------+--------------+--------------------------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM Agents;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
| 2 | Jane Smith | 987-654-3210 | [email protected] |
| 3 | Alice Johnson | 555-123-4567 | [email protected] |
| 4 | John Doe | 123-456-7890 | [email protected] |
| 5 | Alice Johnson | 555-123-4567 | [email protected] |
| 6 | Michael Brown | 111-222-3333 | [email protected] |
| 7 | Emily Davis | 444-555-6666 | [email protected] |
+----+---------------+--------------+--------------------------+
7 rows in set (0.00 sec)

mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,


date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Client_Interests (client_id, property_id)
-> VALUES (1, 1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`client_interests`, CONSTRAINT `client_interests_ibfk_2` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' '2022-
01-01')' at line 2
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Client_Interests (client_id, property_id)
-> VALUES (1, 1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`client_interests`, CONSTRAINT `client_interests_ibfk_2` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' '2022-
01-01')' at line 2
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> SELECT * FROM Properties WHERE id = 1;
Empty set (0.00 sec)

mysql> SELECT * FROM Agents WHERE id = 1;


+----+----------+--------------+------------------+
| id | name | contact_info | email |
+----+----------+--------------+------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
+----+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Clients WHERE id = 1;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
+----+---------------+--------------+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Properties WHERE id = 1;


Empty set (0.00 sec)

mysql> INSERT INTO Properties (address, type, size, price, status, owner_agent_id)
-> VALUES ('123 Main St', 'Residential', 2000.00, 500000.00, 'For Sale', 1);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,


date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> SELECT * FROM Properties;
+----+---------------+-------------+---------+-----------+----------
+----------------+
| id | address | type | size | price | status |
owner_agent_id |
+----+---------------+-------------+---------+-----------+----------
+----------------+
| 6 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
| 7 | 456 Elm St | Commercial | 3500.00 | 850000.00 | For Sale |
2 |
| 8 | 789 Oak St | Residential | 1500.00 | 300000.00 | Sold |
1 |
| 9 | 321 Pine St | Residential | 2500.00 | 600000.00 | For Rent |
3 |
| 10 | 654 Maple Ave | Commercial | 4000.00 | 950000.00 | For Sale |
2 |
| 11 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
+----+---------------+-------------+---------+-----------+----------
+----------------+
6 rows in set (0.00 sec)

mysql> INSERT INTO Properties (address, type, size, price, status, owner_agent_id)
-> VALUES ('123 Main St', 'Residential', 2000.00, 500000.00, 'For Sale', 1);
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM Clients;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
| 2 | Emily Davis | 444-555-6666 | [email protected] |
| 3 | David Wilson | 777-888-9999 | [email protected] |
| 4 | Sarah Miller | 123-123-1234 | [email protected] |
| 5 | James Taylor | 555-555-5555 | [email protected] |
+----+---------------+--------------+--------------------------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM Agents;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
| 2 | Jane Smith | 987-654-3210 | [email protected] |
| 3 | Alice Johnson | 555-123-4567 | [email protected] |
| 4 | John Doe | 123-456-7890 | [email protected] |
| 5 | Alice Johnson | 555-123-4567 | [email protected] |
| 6 | Michael Brown | 111-222-3333 | [email protected] |
| 7 | Emily Davis | 444-555-6666 | [email protected] |
+----+---------------+--------------+--------------------------+
7 rows in set (0.00 sec)

mysql> INSERT INTO Transactions (properties, client_id, agent_id, sale_price, date)


-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1054 (42S22): Unknown column 'properties' in 'field list'
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> INSERT INTO Agent_Managed_Properties (agent_id, property_id)
-> VALUES (1, 1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`agent_managed_properties`, CONSTRAINT
`agent_managed_properties_ibfk_2` FOREIGN KEY (`property_id`) REFERENCES
`properties` (`id`))
mysql> SELECT * FROM agents WHERE id = 1;
+----+----------+--------------+------------------+
| id | name | contact_info | email |
+----+----------+--------------+------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
+----+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM properties WHERE id = 1;


Empty set (0.00 sec)

mysql> INSERT INTO properties (id, property_name, other_columns)


-> VALUES (1, 'Example Property', ...);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '...)' at
line 2
mysql>
mysql> INSERT INTO properties (id, property_name, location)
-> VALUES (1, 'Example Property', 'Example Location');
ERROR 1054 (42S22): Unknown column 'property_name' in 'field list'
mysql> SELECT * FROM properties WHERE id = 1;
Empty set (0.00 sec)

mysql> INSERT INTO properties (id, property_name, location)


-> VALUES
-> (2, 'Another Property', '456 Side St, Othertown'),
-> (3, 'Third Property', '789 High St, Anothertown');
ERROR 1054 (42S22): Unknown column 'property_name' in 'field list'
mysql> DESCRIBE properties;
+----------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| address | varchar(255) | NO | | NULL | |
| type | varchar(255) | NO | | NULL | |
| size | decimal(10,2) | NO | | NULL | |
| price | decimal(10,2) | NO | | NULL | |
| status | varchar(255) | NO | | NULL | |
| owner_agent_id | int | YES | MUL | NULL | |
+----------------+---------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,


date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' '2022-
01-01')' at line 2
mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,
date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`vbj`.`transactions`, CONSTRAINT `transactions_ibfk_1` FOREIGN KEY
(`property_id`) REFERENCES `properties` (`id`))
mysql> SELECT * FROM properties WHERE id = 1; -- For property_id
Empty set (0.00 sec)

mysql> SELECT * FROM clients WHERE id = 1; -- For client_id


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
+----+---------------+--------------+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM agents WHERE id = 1; -- For agent_id


+----+----------+--------------+------------------+
| id | name | contact_info | email |
+----+----------+--------------+------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
+----+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> INSERT INTO properties (id, property_name, location)


-> VALUES (1, 'Example Property', '123 Main St, Anytown');
ERROR 1054 (42S22): Unknown column 'property_name' in 'field list'
mysql> DESCRIBE properties;
+----------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| address | varchar(255) | NO | | NULL | |
| type | varchar(255) | NO | | NULL | |
| size | decimal(10,2) | NO | | NULL | |
| price | decimal(10,2) | NO | | NULL | |
| status | varchar(255) | NO | | NULL | |
| owner_agent_id | int | YES | MUL | NULL | |
+----------------+---------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> INSERT INTO properties (id, adress, type, size, price, status)
-> VALUES (1, '123 Main St', 'Residential', 1500, 500000.00, 'Available');
ERROR 1054 (42S22): Unknown column 'adress' in 'field list'
mysql> INSERT INTO properties (id, address, type, size, price, status,
owner_agent_id)
-> VALUES (1, '123 Main St', 'Residential', 1500, 500000.00, 'Available', 1);
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM properties WHERE id = 1;


+----+-------------+-------------+---------+-----------+-----------
+----------------+
| id | address | type | size | price | status | owner_agent_id
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
| 1 | 123 Main St | Residential | 1500.00 | 500000.00 | Available | 1
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
1 row in set (0.00 sec)

mysql> INSERT INTO Transactions (property_id, client_id, agent_id, sale_price,


date)
-> VALUES (1, 1, 1, 500000.00, '2022-01-01');
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO Client_Interests (client_id, property_id)


-> VALUES (1, 1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' (1, 1)'
at line 2
mysql> SELECT * FROM clients WHERE id = 1; -- Check if the client exists
+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
+----+---------------+--------------+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM properties WHERE id = 1; -- Check if the property exists


+----+-------------+-------------+---------+-----------+-----------
+----------------+
| id | address | type | size | price | status | owner_agent_id
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
| 1 | 123 Main St | Residential | 1500.00 | 500000.00 | Available | 1
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
1 row in set (0.00 sec)

mysql> INSERT INTO Client_Interests (client_id, property_id)


-> VALUES (1, 1);
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM Client_Interests WHERE client_id = 1 AND property_id = 1;


+-----------+-------------+
| client_id | property_id |
+-----------+-------------+
| 1 | 1 |
+-----------+-------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Client_Interests WHERE client_id = 1 AND property_id = 1;


+-----------+-------------+
| client_id | property_id |
+-----------+-------------+
| 1 | 1 |
+-----------+-------------+
1 row in set (0.00 sec)

mysql> INSERT INTO Agent_Managed_Properties (agent_id, property_id)


-> VALUES (1, 1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ' (1, 1)'
at line 2
mysql> SELECT * FROM agents WHERE id = 1; -- Check if the agent exists
+----+----------+--------------+------------------+
| id | name | contact_info | email |
+----+----------+--------------+------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
+----+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM properties WHERE id = 1; -- Check if the property exists


+----+-------------+-------------+---------+-----------+-----------
+----------------+
| id | address | type | size | price | status | owner_agent_id
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
| 1 | 123 Main St | Residential | 1500.00 | 500000.00 | Available | 1
|
+----+-------------+-------------+---------+-----------+-----------
+----------------+
1 row in set (0.00 sec)

mysql> INSERT INTO Agent_Managed_Properties (agent_id, property_id)


-> VALUES (1, 1);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM Agent_Managed_Properties WHERE agent_id = 1 AND property_id =


1;
+----------+-------------+
| agent_id | property_id |
+----------+-------------+
| 1 | 1 |
+----------+-------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Properties;


+----+---------------+-------------+---------+-----------+-----------
+----------------+
| id | address | type | size | price | status |
owner_agent_id |
+----+---------------+-------------+---------+-----------+-----------
+----------------+
| 1 | 123 Main St | Residential | 1500.00 | 500000.00 | Available |
1 |
| 6 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
| 7 | 456 Elm St | Commercial | 3500.00 | 850000.00 | For Sale |
2 |
| 8 | 789 Oak St | Residential | 1500.00 | 300000.00 | Sold |
1 |
| 9 | 321 Pine St | Residential | 2500.00 | 600000.00 | For Rent |
3 |
| 10 | 654 Maple Ave | Commercial | 4000.00 | 950000.00 | For Sale |
2 |
| 11 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
| 12 | 123 Main St | Residential | 2000.00 | 500000.00 | For Sale |
1 |
+----+---------------+-------------+---------+-----------+-----------
+----------------+
8 rows in set (0.00 sec)
mysql> SELECT * FROM Clients;
+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | Michael Brown | 111-222-3333 | [email protected] |
| 2 | Emily Davis | 444-555-6666 | [email protected] |
| 3 | David Wilson | 777-888-9999 | [email protected] |
| 4 | Sarah Miller | 123-123-1234 | [email protected] |
| 5 | James Taylor | 555-555-5555 | [email protected] |
+----+---------------+--------------+--------------------------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM Agents;


+----+---------------+--------------+--------------------------+
| id | name | contact_info | email |
+----+---------------+--------------+--------------------------+
| 1 | John Doe | 123-456-7890 | [email protected] |
| 2 | Jane Smith | 987-654-3210 | [email protected] |
| 3 | Alice Johnson | 555-123-4567 | [email protected] |
| 4 | John Doe | 123-456-7890 | [email protected] |
| 5 | Alice Johnson | 555-123-4567 | [email protected] |
| 6 | Michael Brown | 111-222-3333 | [email protected] |
| 7 | Emily Davis | 444-555-6666 | [email protected] |
+----+---------------+--------------+--------------------------+
7 rows in set (0.00 sec)

mysql> SELECT * FROM Transactions;


+----+-------------+-----------+----------+------------+------------+
| id | property_id | client_id | agent_id | sale_price | date |
+----+-------------+-----------+----------+------------+------------+
| 17 | 1 | 1 | 1 | 500000.00 | 2022-01-01 |
+----+-------------+-----------+----------+------------+------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Client_Interests;


+-----------+-------------+
| client_id | property_id |
+-----------+-------------+
| 1 | 1 |
+-----------+-------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM Agent_Managed_Properties;


+----------+-------------+
| agent_id | property_id |
+----------+-------------+
| 1 | 1 |
+----------+-------------+
1 row in set (0.00 sec)

mysql>

You might also like