Está en la página 1de 2

G ESTIÓ N DE BBDD SINTAXIS BÁSICA DE SQL

CREACIÓN DE BASES DE DATOS CREACIÓN DE TABLAS


CREATE TABLE <identificador>(
<atributo_1><tipo_dato>[DEFAULT <valor>][NOT NULL],
CREATE DATABASE <identificador_bd> <atributo_2><tipo_dato>[DEFAULT <valor>][NOT NULL],
[CHARACTER SET <cjto_caracteres>] …
[COLLATE <colocación>]; <atributo_N><tipo_dato>[DEFAULT <valor>][NOT NULL],
<restricciones a nivel de tabla>
);
ELIMINACIÓN DE BASES DE DATOS RESTRICCIÓN DE CLAVE PRIMARIA
DROP DATABASE <identificador_bd>;
CONSTRAINT <identificador> PRIMARY KEY (atributos)

MODIFICACIÓN DE BASES DE DATOS RESTRICCIÓN DE CLAVE AJENA


ALTER DATABASE <identificador_bd> CONSTRAINT <identificador> FOREIGN KEY (atributos)
[CHARACTER SET <cjto_caracteres>] REFERENCES <tabla_referenciada>(atributos)
[COLLATE <colocación>]; [ON DELETE CASCADE | ON DELETE SET NULL]
MODIFICACIÓN DE TABLAS (Añadir atributo) MODIFICACIÓN DE TABLAS (Cambiar el nombre de atributo) MySQL
ALTER TABLE <identificador_tabla> ALTER TABLE <identificador_tabla>
ADD <definición del atributo> CHANGE <ident_viejo> <definición atributo>
[FIRST| AFTER <atributo>]; [FIRST|AFTER <atributo>];
MODIFICACIÓN DE TABLAS (Eliminar atributo) MODIFICACIÓN DE TABLAS (Cambiar el nombre de atributo) Oracle
ALTER TABLE <identificador_tabla> ALTER TABLE <identificador_tabla>
DROP COLUMN <atributo>; RENAME COLUMN <ident_viejo> TO <ident_nuevo> ;
MODIFICACIÓN DE TABLAS (Eliminar primary key) MODIFICACIÓN DE TABLAS (Cambiar la definición de un atributo)
ALTER TABLE <identificador_tabla> ALTER TABLE <identificador_tabla>
DROP PRIMARY KEY; MODIFY <definición atributo> [FIRST|AFTER <atributo>];
ELIMINACIÓN DE TABLAS MODIFICACIÓN DE TABLAS (Eliminar clave ajena) MySQL
ALTER TABLE <identificador_tabla>
DROP TABLE <identificador_tabla>;
DROP FOREIGN KEY <identificador_constraint>;
RENOMBRADO DE TABLAS MySQL MODIFICACIÓN DE TABLAS (Eliminar constraint) Oracle
RENAME TABLE <ident_old1> TO <ident_new1>,
ALTER TABLE <identificador_tabla>
<ident_old2> TO <ident_new2>,
DROP CONSTRAINT <identificador_constraint>;
… ;
RENOMBRADO DE TABLAS Oracle MODIFICACIÓN DE TABLAS (Añadir constraint)
ALTER TABLE <identificador_tabla>
RENAME <identif_viejo> TO <identif_nuevo>;
ADD <definición de constraint>;
CONSULTA OPERADORES
<,>,<=,>=,<>,= NOT, OR, AND LIKE
SELECT [DISTINCT] <expresión>
FROM <lista_tablas> IN NOT IN BETWEEN … AND …
[WHERE <condición>]
EXISTS NOT EXISTS UNION
[GROUP BY <lista_atributos>
[HAVING <condición_grupo>]] IS NULL IS NOT NULL MINUS (Oracle)
[ORDER BY <lista_atributos> [ASC/DESC]];
ALL ANY INTERSET (Oracle)
FUNCIONES DE AGREGACIÓN
COUNT() MAX( ) MIN( ) SUM( ) AVG( )
CONSULTAS CON VARIAS TABLAS
INNER JOIN NATURAL JOIN CROSS JOIN LEFT OUTER JOIN RIGHT OUTER JOIN

SINTÁSIS BÁSICA DE SQL 1


CREACIÓN DE VISTAS ELIMINACIÓN DE VISTAS
CREATE VIEW identificadorVista [(lista de atributos)] DROP VIEW identificadorVista;
AS <Sentencia SELECT> [WITH CHECK OPTION];
MODIFICACIÓN DE VISTAS INSERCIÓN DE UNA TUPLA
INSERT
ALTER VIEW identificadorVista [(lista de atributos)]
INTO <identificador_tabla> [(<lista_atributos)]
AS <Sentencia SELECT> [WITH CHECK OPTION];
VALUES (<lista_valores>);
INSERCIÓN DE TUPLAS EXTRAIDAS DE OTRA TABLA INSERCIÓN DE VARIAS TUPLAS (MySQL)
INSERT
[INTO] <identificador_tabla> [(<lista_atributos)]
INSERT
VALUES (<lista_valores1>),
INTO <identificador_tabla> [(<lista_atributos)]
(<lista_valores2>),
<instrucción_SELECT>

(<lista_valoresN>);
MODIFICACIÓN DE TUPLAS ELIMINACIÓN DE TUPLAS
UPDATE <identificador_tabla>
SET <identificador_atributo1> =<valor1> [,
DELETE
<identificador_atributo2> =<valor2>,
FROM <identificador_tabla>

[WHERE <condición>];
<identificador_atributoN> =<valorN>]
[WHERE <condición>];

SINTÁSIS BÁSICA DE SQL 2

También podría gustarte