---
title: "CREATE FOREIGN TABLE"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_table/"
---

# CREATE FOREIGN TABLE

Use the CREATE FOREIGN TABLE statement to create a foreign table.

## Synopsis

Use the `CREATE FOREIGN TABLE` command to create a foreign table.

## Syntax

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

```output.ebnf
create_foreign_table ::= CREATE FOREIGN TABLE [ IF NOT EXISTS ] 
                         table_name ( [ foreign_table_elem [ , ... ] ] 
                         )  SERVER server_name 
                         [ OPTIONS ( fdw_options ) ]
```

#### create\_foreign\_table

CREATEFOREIGNTABLEIFNOTEXISTS[table\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#table-name)(,[foreign\_table\_elem](/stable/api/ysql/syntax_resources/grammar_diagrams#foreign-table-elem))SERVER[server\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#server-name)OPTIONS([fdw\_options](/stable/api/ysql/syntax_resources/grammar_diagrams#fdw-options))

## Semantics

Create a new foreign table named *table\_name*. If *table\_name* already exists in the specified database, an error will be raised unless the `IF NOT EXISTS` clause is used.

### Collation

The `COLLATE` clause can be used to specify a collation for the column.

### Server

The `SERVER` clause can be used to specify the name of the foreign server to use.

### Options:

The `OPTIONS` clause specifies options for the foreign table. The permitted option names and values are specific to each foreign data wrapper. The options are validated using the FDW’s validator function.

## Examples

Basic example.

```plpgsql
yugabyte=#  CREATE FOREIGN TABLE mytable (col1 int, col2 int) SERVER my_server OPTIONS (schema 'external_schema', table 'external_table');
```

## See also

- [CREATE FOREIGN DATA WRAPPER](/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_data_wrapper/ "CREATE FOREIGN DATA WRAPPER")
- [CREATE FOREIGN TABLE](/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_table/ "CREATE FOREIGN TABLE")
- [CREATE SERVER](/stable/api/ysql/the-sql-language/statements/ddl_create_server/ "CREATE SERVER")
- [CREATE USER MAPPING](/stable/api/ysql/the-sql-language/statements/ddl_create_user_mapping/ "CREATE USER MAPPING")
- [IMPORT FOREIGN SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_import_foreign_schema/ "IMPORT FOREIGN SCHEMA")
- [ALTER FOREIGN TABLE](/stable/api/ysql/the-sql-language/statements/ddl_alter_foreign_table/ "ALTER FOREIGN TABLE")
- [DROP FOREIGN TABLE](/stable/api/ysql/the-sql-language/statements/ddl_drop_foreign_table/ "DROP FOREIGN TABLE")
