NATIONAL

NATIONAL is a SQL keyword used in data type declarations to specify that CHARACTER, CHAR or VARCHAR character strings should use the national character set. It's suitable for storing multi-language data or when the exact character set and collation order needs to be maintained.

Example

CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY,
EmployeeName CHAR(30),
EmployeeNationality NATIONAL CHAR(50)
);

Output

Query OK, 0 rows affected (0.23 sec)

Explanation

In the example code, NATIONAL CHAR(50) is specified as a column type for EmployeeNationality in the Employee table. NATIONAL CHAR is a data type in SQL that is used to store character string type data, where the character count can be up to the number specified in parenthesis. Specifically, NATIONAL CHAR is a fixed-length character string. Between CHAR and NATIONAL CHAR, their key difference is the usage of the NATIONAL keyword, which ensures that the column will store characters of the national character set.

Example

CREATE TABLE Customers
(
CustomerName NATIONAL CHARACTER VARYING(20),
ContactName NATIONAL CHARACTER(15)
);
INSERT INTO Customers (CustomerName, ContactName)
VALUES (N'Acme Corp', N'John Doe');

Output

Command(s) completed successfully.

Explanation

The NATIONAL keyword in SQL is used to specify that a CHAR, VARCHAR, or TEXT column should use the national character set. The national character set is platform-dependent and allows for the storage of unicode data. In the given example, a table named Customers is created with two columns: CustomerName and ContactName. These columns are defined to use the national character set with a varying number of characters. The N before the string values in the INSERT statement indicates that the string is a unicode string.

Example

CREATE TABLE Employee (
ID int,
FirstName NATIONAL VARCHAR(30),
LastName NATIONAL CHAR(30)
);
INSERT INTO Employee (ID, FirstName, LastName)
VALUES (1, N'John', N'Doe');

Output

Query OK, 1 row affected (0.002 sec)

Explanation

In the example above, a table named ‘Employee’ is created with a column ‘FirstName’ and ‘LastName’ of the type NATIONAL VARCHAR and NATIONAL CHAR respectively. The SQL keyword NATIONAL is used to ensure that the column can store Unicode data, which can represent a huge variety of characters from different languages. Then ‘John’ and ‘Doe’ are inserted into ‘FirstName’ and ‘LastName’ columns respectively.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.