La educación, es un tren que te lleva hacia un futuro exitoso


Código sabado 2-marzo

 

mysql> alter table usuario drop email;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table usuario drop primary key;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(40) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(10) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> alter table usuario add email char(40) not null primary key after nom;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(40) | NO   |     | NULL    |       |
| email | char(40) | NO   | PRI | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(10) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table usuario drop primary key;
Query OK, 0 rows affected (0.20 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table usuario drop email;
Query OK, 0 rows affected (0.20 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(40) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(10) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> alter table usuario modify tel char(15) not null primary key;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(40) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   | PRI | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> alter table usuario modify nom nom_U char(40) not null;
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 'nom_U
char(40) not null' at line 1
mysql> alter table usuario change nom nom_U char(40) not null;
Query OK, 0 rows affected (0.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom_U | char(40) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   | PRI | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> alter table usuario change nom_U nom char(45) not null;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(45) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   | PRI | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table usuario add email char(40) not null;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(45) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   | PRI | NULL    |       |
| email | char(40) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.02 sec)

mysql> alter table usuario drop primary key;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   |     | NULL    |       |
| nom   | char(45) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   |     | NULL    |       |
| email | char(40) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> alter table usuario modify ced char(10) not null primary key;
Query OK, 0 rows affected (0.14 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   | PRI | NULL    |       |
| nom   | char(45) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   |     | NULL    |       |
| email | char(40) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.02 sec)

mysql> alter table usuario drop email;
Query OK, 0 rows affected (0.20 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe usuario;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ced   | char(10) | NO   | PRI | NULL    |       |
| nom   | char(45) | NO   |     | NULL    |       |
| dir   | char(30) | NO   |     | NULL    |       |
| tel   | char(15) | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> show create table usuario;
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
| Table   | Create Table

                                              |
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
| usuario | CREATE TABLE `usuario` (
  `ced` char(10) NOT NULL,
  `nom` char(45) NOT NULL,
  `dir` char(30) NOT NULL,
  `tel` char(15) NOT NULL,
  PRIMARY KEY (`ced`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
1 row in set (0.00 sec)

mysql> alter table usuario rename to cliente;
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
+-------------------+
| Tables_in_almacen |
+-------------------+
| cliente           |
| forma_pago        |
| producto          |
| referencia        |
+-------------------+
4 rows in set (0.02 sec)

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(10) | NO   | PRI | NULL    |       |
| nom   | char(10) | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.02 sec)

mysql> alter table producto add cant int(5) not null;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(10) | NO   | PRI | NULL    |       |
| nom   | char(10) | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
| cant  | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> alter table producto drop cant;
Query OK, 0 rows affected (0.28 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table producto add cant int(5) not null after nom;
Query OK, 0 rows affected (0.20 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(10) | NO   | PRI | NULL    |       |
| nom   | char(10) | NO   |     | NULL    |       |
| cant  | int(5)   | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table producto drop primary key;
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(10) | NO   |     | NULL    |       |
| nom   | char(10) | NO   |     | NULL    |       |
| cant  | int(5)   | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> alter table producto change nom nom_P char(40) not null;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(10) | NO   |     | NULL    |       |
| nom_P | char(40) | NO   |     | NULL    |       |
| cant  | int(5)   | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table producto modify cod_P char(40) not null primary key;
Query OK, 0 rows affected (0.14 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe producto;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| cod_P | char(40) | NO   | PRI | NULL    |       |
| nom_P | char(40) | NO   |     | NULL    |       |
| cant  | int(5)   | NO   |     | NULL    |       |
| val   | int(5)   | NO   |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.02 sec)

Nota: El código que se hizo en la clase no se guardo todo, este código lo hice fuera de clase pero aplico todos los comandos y sintaxis.