NATIONAL
Example
Section titled “Example”CREATE TABLE Employee ( EmployeeID INT PRIMARY KEY, EmployeeName CHAR(30), EmployeeNationality NATIONAL CHAR(50));Output
Section titled “Output”Query OK, 0 rows affected (0.23 sec)Explanation
Section titled “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
Section titled “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
Section titled “Output”Command(s) completed successfully.Explanation
Section titled “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
Section titled “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
Section titled “Output”Query OK, 1 row affected (0.002 sec)Explanation
Section titled “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.