# 6.4.7 CREATE EXTERNAL LINK

Part of: [6 Language](6-language.md) › [6.4 Data Definition Language (DDL)](6-4-data-definition-language-ddl.md)

### Syntax

**CREATE** [**TRUNCATE**] **EXTERNAL** **LINK** [_file_name_] _link_name_ [**,** [_file_name_] _link_name_]\* **TO** _target_file_name_ _object_name_ [**,** _target_file_name_ _object_name_]\*

### Description

Create an HDF5 external link named _link_name_ to a group or dataset named _object_name_ stored in another HDF5 file named _target_file_name_. Multiple external links can be created at once by separating their names with a comma (,). If _link_name_ already exists, it is not overwritten, no subsequent external links are created, and an error is raised. To overwrite an existing external link, specify the keyword TRUNCATE.

### Parameter(s)

_file_name_ – optional string that specifies the name of the HDF5 file in which the external link is to be created. If _file_name_ is specified, the file is opened on the fly, the external link is created within it, and the file is subsequently closed. If not specified, the file currently in use is used instead. As a general rule, in case _file_name_ contains spaces or special characters, it should be enclosed in double quotes (“). Otherwise, if it is not enclosed in double quotes, the link is not created, and an error is raised. This rule also applies to any other HDFql operation that works with file names (e.g. [RENAME FILE](6-4-10-rename-file.md)).

_link_name_ – mandatory string that specifies the name of the HDF5 external link to create. As a general rule, in case _link_name_ contains spaces or special characters, it should be enclosed in double quotes (“). Otherwise, if it is not enclosed in double quotes, the link is not created, and an error is raised. This rule also applies to any other HDFql operation that works with external link names (e.g. [RENAME EXTERNAL LINK](6-4-11-rename.md)).

_target_file_name_ – mandatory string that specifies the name of the HDF5 file in which _object_name_ is stored and to which _link_name_ points. As a general rule, in case _target_file_name_ contains spaces or special characters, it should be enclosed in double quotes (“). Otherwise, if it is not enclosed in double quotes, the link is not created, and an error is raised. This rule also applies to any other HDFql operation that works with file names (e.g. [RENAME FILE](6-4-10-rename-file.md)).

_object_name_ – mandatory string that specifies the name of the HDF5 group or dataset (stored in _file_name_) to which _link_name_ points. As a general rule, in case _object_name_ contains spaces or special characters, it should be enclosed in double quotes (“). Otherwise, if it is not enclosed in double quotes, the link is not created, and an error is raised. This rule also applies to any other HDFql operation that works with external link names (e.g. [RENAME EXTERNAL LINK](6-4-11-rename.md)).

### Return

Nothing

### Example(s)

```hdfql
# use (i.e. open) an HDF5 file named "my_file0.h5" 
USE FILE my_file0.h5

# create an HDF5 group named "my_group0" 
CREATE GROUP my_group0

# create an HDF5 dataset named "my_dataset0" of data type variable-length unsigned int 
CREATE DATASET my_dataset0 AS UNSIGNED VARINT

# create an HDF5 external link named "my_link0" to object "my_group0" in file "my_file0.h5" (the external link will not be overwritten if it already exists)
CREATE EXTERNAL LINK my_link0 TO my_file0.h5 my_group0

# create an HDF5 external link named "my_link1" to object "my_object0" in file "my_file1.h5" (the external link will be overwritten if it already exists)
CREATE TRUNCATE EXTERNAL LINK my_link1 TO my_file1.h5 my_object0

# create two HDF5 external links named "my_link2" and "my_link3" to object "my_object1" in file "my_file1.h5" and object "my_object2" in file "my_file2.h5", respectively (neither external links will be overwritten if they already exist)
CREATE EXTERNAL LINK my_link2, my_link3 TO my_file1.h5 my_object1, my_file2.h5 my_object2

# create an HDF5 external link named "this is a long external link name" to object "my_object3" in file "my_file3.h5" (the external link will not be overwritten if it already exists)
CREATE EXTERNAL LINK "this is a long external link name" TO my_file3.h5 my_object3
```

```hdfql
# use (i.e. open) an HDF5 file named "my_file4.h5" 
USE FILE my_file4.h5

# create an HDF5 external link named "my_link4" in the HDF5 file currently in use (i.e. file "my_file4.h5") to object "my_object4" in file "my_file5.h5"
CREATE EXTERNAL LINK my_link4 TO my_file5.h5 my_object4

# close HDF5 file currently in use (i.e. file "my_file4.h5") 
CLOSE FILE 

# create an HDF5 external link named "my_link5" in file "my_file4.h5" to object "my_object5" in file "my_file6.h5"
CREATE EXTERNAL LINK my_file4.h5 my_link5 TO my_file6.h5 my_object5
```
