Sunteți pe pagina 1din 11

PRIMEROS COMANDOS EN MYSQL:

COMANDO PARA CREAR BASES DE DATOS


mysql> create database miprueba;

COMANDO PARA VER BASES DE DATOS CREADAS

Show databases;

COMANDO PARA USAR UNA BASE DE DATOS


mysql> use miprueba;

COMANDO PARA CREAR LAS TABLAS ENUNA BASE DE DATOS

CREATE TABLE administrador ( id INT PRIMARY KEY, nombre VARCHAR(20), apellido


VARCHAR (20), cedula VARCHAR (10) );

COMANDO PARA VER LAS TABLAS DE UNA BASE DE DATOS


mysql> show tables;

COMANDO PARA VER LOS CAMPOS DENTRO DE LAS TABLAS


mysql> describe administrador; (administrador es el nombre de una tabla)
COMANDO PARA MIRAR LOS REGISTROS QUE EXISTEN EN LOS CAMPOS DE UNA TABLA
mysql> select * from administrador;

COMANDO PARA INGRESAR REGISTROS A UNA TABLA

INSERT INTO administrador (name, apellidos, cédulas) VALUES ("Thomas",


“Martínez”,777788);

COMANDO PARA ELIMINAR BASES DE DATOS

Drop database miprueba

COMANDO PARA SALIR DE LA CONSOLA;

quit

COMANDO PARA MIRA UNA COLUMNA DE UNA TABLA

Select (nombre columna) from (nombre tabla)

COMANDO PARA MIRA 2 O MAS COLUMNA DE UNA TABLA

Sellect (nombre columna1), (nombre columna2) from (nombre tabla)

COMANDO PARA ACTUALIZAR O CAMBIAR EL NOMBRE O REGISTRO DE UNA COLUMNA DE UNA


TABLA

Update (nombre tabla) set (nombre columna) = “el nombre del registro where id = ( Número
donde se ubica el registro)

COMANDO PARA BUSCAR REGISTROS CON IGUAL NOMBRE O CATEGORÍA ENUNA TABLA

Select * from (nombre tabla) where (nombre columna) = “ Nombre de registro en la columna”
COMANDO PARA CAMBIAR DE NOMBRE A UNA TABLA

Rename table (nueva tabla) to (nuevo nombre tabla)

Comando para eliminar una columna de una tabla

Alter table (nombre tabla) drop (nombre columna);

COMANDO PARA HACER UNA RELACION DENTRE TABJAS O CLAVE FORANEA

Alter table  cliente  add  pedido  int (4) references pedido (id);

Nombre taba a Nombre taba


donde va la donde viene la Nombre taba de
relación relación donde viene la
relación

PASO A PASO PARA CREAR TABLAS CON SUS RELACIONES

PASOS PROPIOS EN MYSQL PARA CREAR 2 TABLAS Y SUS RELACIONES

SHOW DATABASES;

CREATE TABLE BDRESTAURANTE;

USE RESTAURANTE;

LUEGO CREA LA PRIMER TABLA (clientes)


LUEGO CREA LA SEGUNDA (PEDIDOS)

LISTA LAS TABLAS

DESCRIBE PEDIDOS QUE ES LA TABLA QUE VA A IR CON LA LLAVE FORANEA A LA OTRA, EN ESTE
CASO CLIENTE, PARA VER LOS CAMPOS CREADOS

INSERTA EN LA TABLA PEDIDO LOS DATOS

LISTA LOS DATOS INCROPORADOS EN LA TABLA PEDIDOS


AHORRA INSERTA EL COMANDO DE MODIFICAR LA TABLA Y CREAR LA RELACIÓN

Alter table cliente add pedido int (4) references pedido (id)

LUISTA LA TABLA CON DESCRIBE Y YA DEBE APARECER LA RELACION

Describe clientes;

AHORA INSERTA EN LA TABLA CLIENTES REGISTROS Y YA APARECE LA RELACIÓN

Insert into cliente ( (NumMesa, nombre, teléfono, pedido) Values (“uno”, “ Juan Mesa”, 887766, 1)

Hace lo mismo 4 veces con diferentes datos ………………………………………………………..

Luego ya puede ver la tabla con la respectiva relación

PARA RELACIONAR LA TERCERA TABLA


DESCRIBE LA TABLA CLIENTE Y YA SE PRESENTA LA RELACION DE LA NUEVA TABLA QUE EN ESTE
CASO ES: TIPOPAGO

LUEGO INSERTA DATOS A LA TABLA

PARA LUEGO VER LA TABLA CON LAS RELACIONES

Las dos tablas


relacionadas:

Pedido y
tipopago

OTRA FORMA DE HACER RELACIONES Y CREAR LA CLAVE FORANEA CON TRES TABLAS

1. CREAR LA BASE DE DATOS


SE CREO LA BASE DE DATOS Y LAS TRES TABLAS. LA TABLA NOTA ES LA QUE TIENEN LAS DOS
LLAVES FORANEAS, LA DE PRODUCTO Y LA DE CLIENTE,

AHORA SE LISTAN

AHORA SE LE INSERTAN DATOS A CADA TABLA


SE LISTA LA TABLA NOTA Y SE PUEDE VER QUE EN LA CLAVE PRODUCTO, SALE LA CLAVE DEL
PRODUCTO DECLARADA EN LA TABLA PRODUCTO Y EN LA CLAVE DEL CLIENTE SALE LA CLAVE DEL
CLIENTE DECLARADA EN LA CLAVE CLIENTE.

LOS DATOS EN SQL


Lenguaje de definición de datos (DDL)

Las sentencias DDL se utilizan para crear y modificar la estructura de las


tablas así como otros objetos de la base de datos.

 CREATE - para crear objetos en la base de datos.

 ALTER - modifica la estructura de la base de datos.

 DROP - borra objetos de la base de datos.

 TRUNCATE - elimina todos los registros de la tabla, incluyendo


todos los espacios asignados a los registros.

Lenguaje de manipulación de datos (DML)

Las sentencias de lenguaje de manipulación de datos (DML) son


utilizadas para gestionar datos dentro de los schemas. Algunos
ejemplos:

 SELECT - para obtener datos de una base de datos.

 INSERT - para insertar datos a una tabla.

 UPDATE - para modificar datos existentes dentro de una tabla.

 DELETE - elimina todos los registros de la tabla; no borra los


espacios asignados a los registros.

TIPOS DE DATOS EN UNA BASE DE DATOS EN MYSQL;

Vamos a repasar los diferentes tipos de dato que podemos almacenar en una
base de datos MySQL.

Antes de comenzar a trabajar y crear bases de datos es necesario saber que tipo
de datos y estructura pueden contener.

Repasando la documentación oficial podríamos dividir en 3 grandes grupos estos


datos:

 Numéricos
 Fecha
 String
Distingue entre minúculas y mayúsculas.

 MEDIUMTEXT:Una longitud máxima de 16.777.215 caracteres. Sirve para


almecenar texto plano sin formato. Distingue entre minúculas y mayúsculas.
 LONGTEXT: Una longitud máxima de 4.294.967.298 caracteres. Sirve para
almecenar texto plano sin formato. Distingue entre minúculas y mayúsculas.

S-ar putea să vă placă și