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
Output
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
Output
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
Output
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.