Fundamentos de Bases de datos
Cómo diseñar bases de datos y hacer queries efectivos
Cómo identificar y organizar datos en bases de datos
Introducción práctica a SQL y bases de datos relacionales
Trabajo Directo con MySQL: Cliente, Servidor y Manejo de Errores
Instalación de MySQL en varios sistemas operativos
Quiz: Fundamentos de Bases de datos
Introducción a Bases de Datos Relacionales
Conceptos básicos de bases de datos: columnas, tuplas y relaciones
Creación de Tablas en MySQL con Tipos de Datos Esenciales
Creación de tablas en MySQL con Primary Key y Timestamp
Normalización y relaciones en bases de datos relacionales
Creación y visualización de bases de datos con DBML y DBDiagram
Quiz: Introducción a Bases de Datos Relacionales
Manipulación de Datos
Cómo crear tablas y utilizar 'Foreign Keys' en MySQL
Crear tablas y establecer llaves foráneas en SQL
Tipos de tablas en una base de datos relacional
Cómo Modificar Tablas en SQL con ALTER TABLE
Cómo Insertar Datos y Manejar Errores en MySQL
Creación Avanzada de una Tabla Products en MySQL
Uso práctico del WHERE en SQL para filtrar datos con precisión
Guía práctica para modificar datos usando UPDATE en SQL
Cómo eliminar datos en SQL: métodos lógicos y físicos
Uso Avanzado del Comando SELECT en SQL
Quiz: Manipulación de Datos
Agrupación de Datos
Funciones agregadoras en MySQL para análisis eficiente de datos
Insertar datos desde otra tabla en MySQL con Insert Into Select
Cómo utilizar Left Join en bases de datos relacionales
Cómo consultar y relacionar tablas en MySQL
You don't have access to this class
Keep learning! Join and start boosting your career
SQL offers a natural and clear way to manage databases, especially when it comes to creating tables and defining relationships between them. Understanding how the basic commands work to create tables, assign data types, set unique columns and handle relationships withforeign keys is fundamental to build an efficient and organized structure.
The basic command to create a table in MySQL starts with:
CREATE TABLE IF NOT EXISTS table_name ( column DataType Constraints, ...);
When creating a table, it is advisable to clearly name the columns according to what they contain, using specific nouns:
ProductID
rather than simply ID
.The slug
field is especially relevant for improving URL accessibility. It should be kept unique because:
Practical example of creating a slug field:
slug VARCHAR(200) NOT NULL UNIQUE
When you expect to store long or unknown length texts, use the TEXT
data type:
description TEXT NULL
A foreign key
creates a strict relationship between tables, allowing to maintain referential integrity:
Simple example:
FOREIGN KEY (ClientID) REFERENCES Clients(ClientID)
The ENUM
data type allows you to define specific states for a column:
(OPEN
).status ENUM('OPEN', 'PAID', 'LOST') NOT NULL DEFAULT 'OPEN'
Note that modifying an ENUM at a later time may require direct adjustments to the database, as well as previous updates to existing data.
Using ON UPDATE CASCADE
and ON DELETE CASCADE
on foreign keys makes it possible to:
However, it must be done cautiously, as the example shows:
FOREIGN KEY (ClientID) REFERENCES Clients(ClientID)ON UPDATE CASCADEON DELETE CASCADE
To check the current creation and structure of a table, use:
SHOW CREATE TABLE table_name;
This instruction clearly exposes the keys and constraints applied.
We invite you to put this knowledge into practice by creating your own tables and relationships. Have you encountered any particular challenge implementing these commands? Share your experience and any questions in the comments.
Contributions 4
Questions 0
Want to see more contributions, questions and answers from the community?