The NAMES keyword appears in the SET statement (SET NAMES) to tell the database which character set the client is using and, optionally, which collation should apply to string literals sent during the current session. When executed, the server adjusts the variables that govern parsing and result encoding so that text is interpreted and returned correctly. In MySQL and MariaDB, SET NAMES simultaneously updates character_set_client, character_set_connection, and character_set_results. PostgreSQL treats SET NAMES as a shorthand for SET client_encoding. Changing the connection character set does not convert existing stored data; it only affects how incoming and outgoing text is encoded for this session. The command is transaction-independent and takes effect immediately.
collation_name
- STRING (Optional) Specific collation from the chosen character set.SET character_set_client, SET client_encoding, CHARACTER SET, COLLATE, SHOW CHARACTER SET
MySQL 4.1.0 (2003)
No. It only affects how text is sent to and retrieved from the server during the current session.
Yes. Append COLLATE 'collation_name' to control comparison and ordering rules.
It is supported in MySQL, MariaDB, and PostgreSQL (as an alias). SQL Server, Oracle, and SQLite do not recognize it.
Many clients require quotes. Omitting them may raise a syntax error or treat the identifier as a column name.