06.09.2014 Views

Bases de datos: Software libre - Universitat Oberta de Catalunya

Bases de datos: Software libre - Universitat Oberta de Catalunya

Bases de datos: Software libre - Universitat Oberta de Catalunya

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

© FUOC • 71Z799014MO 42 <strong>Bases</strong> <strong>de</strong> <strong>datos</strong> en PostgreSQL<br />

4.5. In<strong>de</strong>xación<br />

PostgreSQL crea índices para las llaves primarias <strong>de</strong> todas las tablas. Cuando se necesite<br />

crear índices adicionales, utilizaremos la expresión <strong>de</strong>l ejemplo siguiente:<br />

create in<strong>de</strong>x persona_nombre_indice on Persona ( nombre );<br />

4.6. Consulta <strong>de</strong> información <strong>de</strong> bases <strong>de</strong> <strong>datos</strong> y tablas<br />

Como ya sabemos, el cliente psql ofrece varias alternativas para obtener información<br />

sobre la estructura <strong>de</strong> nuestra base <strong>de</strong> <strong>datos</strong>. En la siguiente tabla se<br />

muestran algunos comandos <strong>de</strong> mucha utilidad.<br />

Comando<br />

Descripción<br />

\l Lista las bases <strong>de</strong> <strong>datos</strong><br />

\d Describe las tablas <strong>de</strong> la base <strong>de</strong> <strong>datos</strong> en uso<br />

\ds<br />

Lista las secuencias<br />

\di<br />

Lista los índices<br />

\dv<br />

Lista las vistas<br />

\dp \z Lista los privilegios sobre las tablas<br />

\da<br />

Lista las funciones <strong>de</strong> agregados<br />

\df<br />

Lista las funciones<br />

\g archivo Ejecuta los comandos <strong>de</strong> archivo<br />

\H Cambia el modo <strong>de</strong> salida HTML<br />

\! comando Ejecuta un comando <strong>de</strong>l sistema operativo<br />

Para obtener la lista <strong>de</strong> tablas <strong>de</strong> la base <strong>de</strong> <strong>datos</strong> <strong>de</strong>mo hacemos lo siguiente:<br />

<strong>de</strong>mo=# \d<br />

List of relations<br />

Name |Type | Owner<br />

---------------------+----------+--------<br />

ganancia | table | postgres<br />

precios | table | postgres<br />

productos | table | postgres<br />

productos_clave_seq | sequence | postgres<br />

proveedores | table | postgres<br />

(5 rows)<br />

La estructura <strong>de</strong> la tabla productos se solicita <strong>de</strong> la siguiente manera.<br />

<strong>de</strong>mo=# \d productos<br />

Table “productos”<br />

Column |Type | Modifiers<br />

--------------+---------------------+-------------------------------------------<br />

parte |character varying(20)|<br />

tipo |character varying(20)|<br />

especificación|character varying(20)|<br />

psugerido | real |<br />

clave |integer<br />

|not null <strong>de</strong>fault nextval(‘”productos_clave_seq”‘::text)<br />

Primary key: productos_pkey<br />

Triggers: RI_ConstraintTrigger_17342,<br />

RI_ConstraintTrigger_17344

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!