> For the complete documentation index, see [llms.txt](https://skilly.gitbook.io/postgresql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://skilly.gitbook.io/postgresql/teoria-11/13_manejando_restricciones.md).

# Restricciones

## Crear

```sql
CREATE TABLE productos (
    id SERIAL PRIMARY KEY,
    nombre VARCHAR(50) NOT NULL,
    precio NUMERIC(10,2),
    descripcion TEXT,
    CONSTRAINT uk_nombre UNIQUE (nombre)
);
```

## Añadir

```sql
ALTER TABLE productos
ADD CONSTRAINT no_nulo_nombre
CHECK (nombre IS NOT NULL);
```

> :pencil: **NOTA** a diferencia de MySQL, en PostgreSQL se utiliza la cláusula "CHECK" en lugar de "NOT NULL" para definir restricciones de no nulidad.

## Modificar

```sql
ALTER TABLE clientes ALTER COLUMN email TYPE VARCHAR(255), 
ALTER COLUMN email SET NOT NULL;
```

## Eliminar

```sql
DROP INDEX clientes_email_idx;
```
