---
title: "IMPORT FOREIGN SCHEMA"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/ddl_import_foreign_schema/"
---

# IMPORT FOREIGN SCHEMA

Use the IMPORT FOREIGN SCHEMA statement to import tables from a foreign schema.

## Synopsis

Use the `IMPORT FOREIGN SCHEMA` command to create foreign tables that represent tables in a foreign schema on a foreign server. The newly created foreign tables are owned by the user who issued the command. By default, all the tables in the foreign schema are imported. However, the user can specify which tables to import using the `LIMIT TO` and `EXCEPT` clauses. To use this command, the user must have `USAGE` privileges on the foreign server, and `CREATE` privileges on the target schema.

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-1)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-1)

```output.ebnf
import_foreign_schema ::= IMPORT FOREIGN SCHEMA remote_schema  
                          [ { LIMIT TO | EXCEPT } ( table_name [ ... ] 
                            ) ]  FROM SERVER server_name INTO 
                          local_schema  [ OPTIONS ( fdw_options ) ]
```

#### import\_foreign\_schema

IMPORTFOREIGNSCHEMA[remote\_schema](/stable/api/ysql/syntax_resources/grammar_diagrams#remote-schema)LIMITTOEXCEPT([table\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#table-name))FROMSERVER[server\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#server-name)INTO[local\_schema](/stable/api/ysql/syntax_resources/grammar_diagrams#local-schema)OPTIONS([fdw\_options](/stable/api/ysql/syntax_resources/grammar_diagrams#fdw-options))

## Semantics

Create foreign tables (in *local\_schema*) that represent tables in a foreign schema named *remote\_schema* located on a foreign server named *server\_name*.

### LIMIT TO

The `LIMIT TO` clause can be optionally used to specify which tables to import. All other tables will be ignored.

### EXCEPT

The `EXCEPT` clause can be optionally used to specify which tables to *not* import. All other tables will be ignored.

## See also

- [CREATE SERVER](/stable/api/ysql/the-sql-language/statements/ddl_create_server "CREATE SERVER")
- [CREATE FOREIGN TABLE](/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_table "CREATE FOREIGN TABLE")
- [IMPORT FOREIGN SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_import_foreign_schema "IMPORT FOREIGN SCHEMA")
