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

SQL 2

The document details a MySQL session where a user connects to a database, creates tables, and performs various operations such as inserting, updating, and deleting records. The user creates tables for 'parte', 'proyecto', and 'envio', and populates them with data including parts and projects. Additionally, the user modifies data in the 'proyecto' table and deletes a record from the 'proveedor' table.

Uploaded by

brisa olimar
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)
3 views3 pages

SQL 2

The document details a MySQL session where a user connects to a database, creates tables, and performs various operations such as inserting, updating, and deleting records. The user creates tables for 'parte', 'proyecto', and 'envio', and populates them with data including parts and projects. Additionally, the user modifies data in the 'proyecto' table and deletes a record from the 'proveedor' table.

Uploaded by

brisa olimar
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/ 3

labso03@labso03-ROG-STRIX-G10CE-G10CE:~$ mysql -u root -h localhost -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.42-0ubuntu0.24.04.1 (Ubuntu)

Copyright (c) 2000, 2025, 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> show databases;


+--------------------+
| Database |
+--------------------+
| MiBD |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0,02 sec)

mysql> use MiBD;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_MiBD |
+----------------+
| MiTabla |
| proveedor |
+----------------+
2 rows in set (0,00 sec)

mysql> create table parte(


-> idparte varchar(4),
-> nombre varchar(20),
-> color varchar(20),
-> peso integer,
-> ciudad varchar(20), primary key(idparte));
Query OK, 0 rows affected (0,96 sec)

mysql> select *from parte;


Empty set (0,00 sec)

mysql> insert into parte values("P1","Tuerca","rojo",12,"Londres");


Query OK, 1 row affected (0,09 sec)

mysql> insert into parte values("P2","Perno","verde",17,"Paris");


Query OK, 1 row affected (0,12 sec)

mysql> insert into parte values("P3","Tornillo","azul",17,"Roma");


Query OK, 1 row affected (0,08 sec)
mysql> select *from parte;
+---------+----------+-------+------+---------+
| idparte | nombre | color | peso | ciudad |
+---------+----------+-------+------+---------+
| P1 | Tuerca | rojo | 12 | Londres |
| P2 | Perno | verde | 17 | Paris |
| P3 | Tornillo | azul | 17 | Roma |
+---------+----------+-------+------+---------+
3 rows in set (0,00 sec)

mysql> create table proyecto(


-> idproy varchar(4),
-> nombre varchar(20),
-> ciudad varchar(20),primary key(idproy));
Query OK, 0 rows affected (0,45 sec)

mysql> insert into proyecto values("Y1","Clasificador","Paris");


Query OK, 1 row affected (0,09 sec)

mysql> insert into proyecto values("Y2","Monitor","Roma");


Query OK, 1 row affected (0,09 sec)

mysql> insert into proyecto values("Y3","OCR","Atenas");


Query OK, 1 row affected (0,09 sec)

mysql> select *from proyecto;


+--------+--------------+--------+
| idproy | nombre | ciudad |
+--------+--------------+--------+
| Y1 | Clasificador | Paris |
| Y2 | Monitor | Roma |
| Y3 | OCR | Atenas |
+--------+--------------+--------+
3 rows in set (0,00 sec)

mysql> insert into proyecto values("Y4","Consola","Atenas");


Query OK, 1 row affected (0,08 sec)

mysql> select *from proyecto;


+--------+--------------+--------+
| idproy | nombre | ciudad |
+--------+--------------+--------+
| Y1 | Clasificador | Paris |
| Y2 | Monitor | Roma |
| Y3 | OCR | Atenas |
| Y4 | Consola | Atenas |
+--------+--------------+--------+
4 rows in set (0,00 sec)

mysql> create table envio(


-> idprov varchar(4),
-> idparte varchar(4),
-> idproy varchar(4),
-> cant integer);
Query OK, 0 rows affected (0,49 sec)

mysql> alter table envio add primary key(idprov, idparte,idproy);


Query OK, 0 rows affected (1,37 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table envio add foreign key (idprov) references proveedor(idprov);
Query OK, 0 rows affected (1,47 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table envio add foreign key (idparte) references parte(idparte);
Query OK, 0 rows affected (1,55 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql>
mysql> alter table envio add foreign key (idparte) references parte(idparte);
mysql> alter table envio add foreign key (idproy) references proyecto(idproy);
Query OK, 0 rows affected (2,04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into envio values("V1","P1","Y1","200");


Query OK, 1 row affected (0,12 sec)

mysql> insert into envio values("V1","P1","Y4","700");


Query OK, 1 row affected (0,09 sec)

mysql> update proyecto set ciudad="Oaxaca" where ciudad="Atenas";


Query OK, 2 rows affected (0,08 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from proyecto;


+--------+--------------+--------+
| idproy | nombre | ciudad |
+--------+--------------+--------+
| Y1 | Clasificador | Paris |
| Y2 | Monitor | Roma |
| Y3 | OCR | Oaxaca |
| Y4 | Consola | Oaxaca |
+--------+--------------+--------+
4 rows in set (0,00 sec)

mysql> delete from proveedor where nombre="Blake";


Query OK, 1 row affected (0,11 sec)

mysql> select * from proveedor;


+--------+--------+--------+---------+
| idprov | nombre | status | ciudad |
+--------+--------+--------+---------+
| V1 | Smith | 20 | Londres |
| V2 | Jones | 10 | Paris |
| V4 | Clark | 20 | Londres |
| V5 | Adams | 30 | Atenas |
+--------+--------+--------+---------+
4 rows in set (0,00 sec)

mysql>
mysql>

You might also like