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
Approaching a realistic database involves thinking about how to design tables closer to the practical needs of the market. You will learn how to rebuild a products table incorporating fundamental elements such as SKU and automatic timestamps, as well as understand how to correctly optimize the massive insertion of data.
A useful and real-world structure of a products
table must include certain key elements. These elements allow you to clearly identify each product and manage its information efficiently in everyday situations.
product ID
: integer, unsigned, primary key autoincremental.SKU
: globally unique product identifier, varchar type.name
: descriptive name of the product.slug
: URL friendly identifier, unique.description
: detailed text about the product.price
: monetary value of the product, can be optional.created_at
and modified_at
: timestamps for automatic tracking.The appropriate SQL statement to create this table would be a simple but powerful structure:
CREATE TABLE IF NOT EXISTS products ( product_ID INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT, SKU VARCHAR(20) NOT NULL UNIQUE, name VARCHAR(50) NOT NULL, slug VARCHAR(50) NOT NULL UNIQUE,
description TEXT, price DOUBLE(10,2), created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, modified_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
When handling the insertion of thousands of records, it is critical to understand the importance of efficient management of system resources. Doing this correctly ensures overall performance stability, especially in real productions where multiple users are connected simultaneously.
The recommended practice is to insert in small blocks or chunks:
A valuable skill in development is to manage databases through the terminal. To insert data from an external file into MySQL, the example would be as follows:
echo "INSERT INTO products (SKU, name, slug, description, description, price) VALUES (...)" > file.sql
mysql -u user -p -D database < file.sql
This method allows you to execute SQL commands directly and is useful for large volumes of data or automated scripts.
When bulk inserting it is usual to encounter conflicts such as duplicates in single columns (e.g. SKU or slug). You can easily handle this situation by using the INSERT IGNORE
statement, which ignores and continues with the insertion of valid records, omitting only the conflicting rows.
Finally, analyzing how many records were actually inserted is accomplished with a simple query:
SELECT COUNT(*) FROM products;
What techniques do you currently use to optimize your databases? Share your strategies in the comments.
Contributions 4
Questions 0
Want to see more contributions, questions and answers from the community?