Sistema Academico
Lic. Silvio Gamarra
SQL(1)
(...la guía básica de supervivencia de dmi)
Universidad Nacional de Villarrica del Espiritu Santo
Octubre 2012 1
El estándar SQL
Year 1986 1989 1992 1999 2003 Name SQL-86 SQL-89 SQL-92 SQL:1999 SQL:2003 Alias SQL-87 FIPS SQL2, FIPS 127-2 SQL3 Comments First published by ANSI. Ratified by ISO in 1987. Minor revision, adopted as FIPS 127-1.
UNVESLic. Robert Araujo
2006 2008
SQL:2006
SQL:2008
Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2. Added regular expression matching, recursive queries, triggers, support for procedural and control-of-flow statements, non-scalar types, and some object-oriented features. Introduced XML-related features, window functions, standardized sequences, and columns withauto-generated values (including identity-columns). ISO/IEC 9075-14:2006 defines ways in which SQL can be used in conjunction with XML. It defines ways of importing and storing XML data in an SQL database, manipulating it within the database and publishing both XML and conventional SQL-data in XML form. In addition, it provides facilities that permit applications to integrate into their SQL code the use ofXQuery, the XML Query Language published by the World Wide Web Consortium (W3C), to concurrently access ordinary SQL-data and XML documents. Legalizes ORDER BY outside cursor definitions. Adds INSTEAD OF triggers. Adds the TRUNCATE statement.cite_refiablog.sybase.com-paulley_12-0cite_ref-iablog.sybase.compaulley_12-0[13]
2
El estándar SQL
UNVES
Lic. Robert Araujo
Hoy en día lamayoría de los sistemas de gestión de bases de datos soportan el estándar de SQL... y bueno... más o menos... al menos algo que está bastante cerca
3
Conectarse a una Base de Datos
postgres=# CREATE DATABASE prueba; CREATE DATABASE prueba=# \l List of databases Name | Owner | Encoding -----------+----------+---------postgres | postgres | UTF8 prueba | postgres | UTF8 template0 | postgres | UTF8template1 | postgres | UTF8 (4 rows)
UNVES
Lic. Robert Araujo
\c se usa para conectarse (usar) una BD existente
postgres=# \c prueba You are now connected to database "prueba". prueba=# Esto varía mucho a lo largo de los distintos manejadores de BD, por ejemplo, en MySQL es USE prueba
4
Crear una Tabla (Esquema de Relación) (1) (Lo Básico)
prueba=# CREATE TABLE persona ( prueba(#cedula INT, prueba(# nombre VARCHAR(50), prueba(# apellido VARCHAR(50), prueba(# fecha_nac DATE prueba(# ); CREATE TABLE prueba=#
UNVES
Lic. Robert Araujo
prueba=# CREATE TABLE persona ( cedula INT, nombre VARCHAR(50), apellido VARCHAR(50), fecha_nac DATE ); CREATE TABLE prueba=#
\dt se usa para listar las tablas existentes en la BD actual
prueba=# \dt List of relations Schema | Name| Type | Owner --------+---------+-------+---------public | persona | table | postgres (1 row) prueba=#
Opps, pero se nos olvidó la clave primaria...
5
SQL (Tipos de Datos (1)
Nombre bigint bigserial bit [ (n) ] bit varying [ (n) ] boolean box bytea character varying [ (n) ] character [ (n) ] cidr Alias int8 serial8 varbit bool Description Exact numeric of selectable precisionautoincrementing eightbyte integer fixed-length bit string variable-length bit string logical Boolean (true/false) rectangular box on a plane binary data ("byte array")
UNVES
Lic. Robert Araujo
Descripción Numero entero Entero autoincremental Cadena de bits de longitud fija Cadena de bits de longitud fija Lógico (verdadero/falso) Caja rectangular en un plano Arreglo binario de datos Caracter delongitud variable Caracter de longitud fija Dirección IPv4 o IPv6
6
varchar [ variable-length character (n) ] string char [ (n) ] fixed-length character string IPv4 or IPv6 network address
SQL (Tipos de Datos (2)
Nombre circle date double precision inet integer interval [ fields ] [ (p) ] line lseg macaddr money numeric [ (p, s) ] Alias float8 int, int4 decimal [ (p,...
Regístrate para leer el documento completo.