mirror of
https://github.com/supabase/supabase.git
synced 2026-05-31 01:42:45 +08:00
114 lines
1.9 KiB
Plaintext
114 lines
1.9 KiB
Plaintext
---
|
|
id: schemas
|
|
title: "Schemas"
|
|
slug: schemas
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabsPanel from '@theme/TabsPanel';
|
|
|
|
Schemas are like "folders". They help to keep your database organized.
|
|
|
|
Schemas are particularly useful for security. You can set different permissions on each schema.
|
|
For example, you might want to use a `public` schema for user-facing data, and an `auth` schema for all logins and secured data.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="sql"
|
|
groupId="reference/postgres"
|
|
values={[{ label: 'SQL', value: 'sql' }]}>
|
|
|
|
<TabsPanel id="sql" label="sql">
|
|
|
|
```sql
|
|
create schema schema_name;
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
- Schemas contain [tables](/docs/reference/postgres/tables), columns, triggers, functions, etc.
|
|
- Postgres comes with a `public` schema set up by default.
|
|
- It is best practice to use lowercase and underscores when naming schemas. For example: `schema_name`, not `Schema Name`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Creating a schema
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="sql"
|
|
groupId="reference/postgres"
|
|
values={[{ label: 'SQL', value: 'sql' }]}>
|
|
|
|
<TabsPanel id="sql" label="sql">
|
|
|
|
```sql
|
|
create schema schema_name;
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Removing a schema
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="sql"
|
|
groupId="reference/postgres"
|
|
values={[{ label: 'SQL', value: 'sql' }]}>
|
|
|
|
<TabsPanel id="sql" label="sql">
|
|
|
|
```sql
|
|
drop schema if exists schema_name;
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Using special characters
|
|
|
|
Although it's not recommended, you can use uppercase and spaces when naming your schema by wrapping the name with double-quotes.
|
|
As a result, you will always need to use double-quotes when referencing your schema.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="sql"
|
|
groupId="reference/postgres"
|
|
values={[{ label: 'SQL', value: 'sql' }]}>
|
|
|
|
<TabsPanel id="sql" label="sql">
|
|
|
|
```sql
|
|
create schema "Schema Name";
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs> |