35
Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

Embed Size (px)

Citation preview

Page 1: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

Ing. Eddye Sánchez Castillo

FACULTAD DE INGENIERIAEscuela Profesional de Computación y

SistemasBASE

DE DATOS

I

Page 2: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLLas principales temas de este capitulo son:

Iniciar MysqlIngresar a MysqlAsignar una clave al usuario rootAcceso a la información básicaEl lenguaje SQLAdministración de usuarios

Page 3: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLIngresar a MySql por el Botón INICIO de Windows

Page 4: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I
Page 5: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I
Page 6: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I
Page 7: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLTambién puede entrar por el botón Inicio/ejecutar y en la ventana que se visualiza escribir cmd.

Page 8: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLTambién puede entrar por el botón Inicio/ejecutar y en la ventana que se visualiza escribir cmd.

Page 9: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLSe necesita ingresar a la carpeta bin de Mysql.

Page 10: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLComando para ingresar a Mysql: mysql –u usuarioEl usuario predeterminado se llama root

Page 11: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

BASES DE DATOS MYSQLEl prompt mysql indica que usted ya ingreso al administrador de Base de datos Mysql. Cada comando que escriba debe terminar con punto y coma (;).

Page 12: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ACCESO A LA INFORMACIÓN BÁSICADespués de conectarse a Mysql, usted ya puede escribir los

comandos para administrar las bases de datos.User():Esta función permite visualizar el nombre del usuario que esta conectado a Mysql.

Page 13: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ACCESO A LA INFORMACIÓN BÁSICAVersion():Esta función permite visualizar la version de Mysql que usted esta utilizando.

Page 14: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ACCESO A LA INFORMACIÓN BÁSICACurrent_Date:Esta función devuelve la fecha del servidor.

Page 15: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ACCESO A LA INFORMACIÓN BÁSICANow():Esta función devuelve la fecha y hora del servidor.

Page 16: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

EL LENGUAJE SQLEsta formado por un conjunto de comandos que nos permite acceder y administrar una base de datos y todos sus objetos.SQL es un lenguaje de consulta universal para base de datos, es decir se puede utilizar en otros administradores de base de datos como Access, SQL server, Mysql, FoxPro, etc.Los comandos SQL se dividen en dos grupos:Lenguaje de definición de datos:(DDL) permite crear, modificar y eliminar los objetos de una DBF.Lenguaje de Manipulación de Datos:(DML) Permite manejar la información almacenada, agregar registros, actualizarlos, leerlos, etc.

Page 17: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR BASE DE DATOSPermite crear Base de Datos en MysqlSintaxis:

Nombre:Es el nombre de la base de datos que se desea crear, al crear el mensaje Query OK significa que se ha realizado la consulta con exitoy la Base de Datos esta creada.

Create DataBase Nombre;

Page 18: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR BASE DE DATOS

Page 19: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

VISUALIZAR BASE DE DATOSPara visualizar las bases de datos creadas en Mysql y confirmar la creación de la nueva base de datos se utiliza el siguiente comando:Show

DataBases;

Page 20: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

VISUALIZAR BASE DE DATOSUSE: Este comando se utiliza para indicar a MySql la base de datos que deseamos utilizarUse

BaseDatos;

Page 21: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASCreate TableEste comando permite crear tablas dentro de una base de datos: su sintaxis es:

Create Table Nombre de la Tabla( Estructura de la tabla)

Dentro de la Estructura de la Tabla se escribe cada uno de los campos que formaran la nueva tabla con su respectivo tipo de datos y longitud.

Page 22: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASTIPOS DE DATOS NUMERICOS

TinyIntPermite almacenar datos enteros (sin decimales) con o sin signo. Con signo acepta entre -128 a 127 y sin signo entre 0 a 255. ocupa 1 byte.

Bit o BoolPermite almacenar solo los números 0 y 1. Se puede utilizar como un campo lógico.

SmallntTambién acepta números enteros con o sin signo. Con signo desde -32768 a 32767 y sin signo entre 0 y 65535. Ocupa 2 byte.

Page 23: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASTIPOS DE DATOS NUMERICOS

MediumintAcepta números enteros con o sin signo. Con signo entre -8,388,608 y 8,388,607 y sin signo entre 0 y 16777215. Ocupa 3 bytes.

Integer o intAcepta números enteros con o sin signo. Con signo -2147483648 a 2147483647 y sin signo es de 0 a 4,294,967,295. Ocupa 4 bytes.

BigintSe utiliza para almacenar números enteros con o sin signo:Con Signo: -9,223,372,036,854,775,808 y 9,223,372,036,854,775,807Sin Signo entre 0 y 18,446,744,073,709,551,615. Ocupa 8 Byte.Float

Double

Page 24: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASTIPOS DE DATOS FECHA

DatePermite almacenar fecha entre 01.01.1001 hasta 31.12.9999 su formato es aa.mm.dd

DateTimePermite almacenar fecha entre 01.01.1001 con ohoras, o minutos y o segundos hasta 31.12.9999 con 23 horas, 59 minutos y 59 segundos, su formato es aa.mm.dd hh.mm.ss

TimeStampAcepta combinación de fecha y hora. El rango es del 01.01.1970 hasta el 2037. Ocupa 4 Bytes.

Page 25: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASTIPOS DE DATOS FECHA

TimePermite almacenar solo horas con el formato HH:MM:SS

YearPermite almacenar solo el año de una fecha desde 1901 hasta el 2015.

Page 26: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASTIPOS DE DATOS CADENA

CharPermite almacenar de 0 a 255 caracteres de longitud fijaVarcharPermite almacenar de 0 a 255 caracteres de longitud variableText o BlobPermite almacenar hasta 65535 caracteres de longitudMediumBlob o MediumTextPermite almacenar hasta 16,777,215 caracteres de longitud.LongBlob o LongTextPermite almacenar hasta 4,294,967,925 caracteres de longitud.

Page 27: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR TABLASCrear una tabla llamada Clientes dentro de la base de datos Empresa, de forma simple, sin clave primaria.

Page 28: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ELIMINAR TABLASDrop Table Nombre de la tabla; elimina físicamente la tabla y sus registros que contiene

Page 29: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR CLAVE PRIMARIA

Page 30: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

CREAR CLAVE PRIMARIA

Page 31: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

VISUALIZAR ESTRUCTURA DE UNA TABLAEl comando DESCRIBE permite visualizar la estructura de una tabla.

Page 32: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

VISUALIZAR ESTRUCTURA DE UNA TABLA

Page 33: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

MODIFICAR ESTRUCTURA DE UNA TABLA

Page 34: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

ELIMINAR CAMPO DE UNA TABLA

Page 35: Ing. Eddye Sánchez Castillo FACULTAD DE INGENIERIA Escuela Profesional de Computación y Sistemas BASE DE DATOS I

AGREGAR CAMPO DE UNA TABLA