SQL Keywords

SQL TRAILING

What is the SQL TRAILING keyword?

Keyword used inside the TRIM function to remove characters only from the end (right side) of a string.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL TRAILING:

SQL TRAILING Full Explanation

TRAILING is part of the ANSI-SQL TRIM specification. When used inside TRIM, it tells the database engine to strip the specified character (or the default space) only from the rightmost end of the input string. Unlike LEADING (left side) or BOTH (both sides), TRAILING focuses exclusively on the string’s tail. The keyword is not a standalone statement; it must appear inside the TRIM function. If no trim character is supplied, spaces are assumed. Many databases also accept the shorter form TRIM(TRAILING FROM string) or the two-argument form TRIM(TRAILING trim_char FROM string).

SQL TRAILING Syntax

TRIM(TRAILING [trim_character] FROM string);
-- shorthand allowed in some dialects
TRIM(TRAILING FROM string);

SQL TRAILING Parameters

  • trim_character (string) - Optional. Single character (or string in some dialects) to remove. Default is space.
  • string (string) - Required. The source string from which to remove trailing characters.

Example Queries Using SQL TRAILING

-- Remove trailing spaces
SELECT TRIM(TRAILING FROM 'Galaxy   ');

-- Remove trailing zeros
SELECT TRIM(TRAILING '0' FROM '1234000');

-- Column usage
SELECT TRIM(TRAILING 'x' FROM username) AS cleaned_name
FROM users;

Expected Output Using SQL TRAILING

  • Each query returns the input string with the specified trailing characters removed
  • No other part of the string is altered

Use Cases with SQL TRAILING

  • Cleaning user-entered data that contains accidental trailing spaces
  • Normalizing numeric codes with trailing padding characters
  • Preparing strings for comparison or indexing where extraneous right-side characters cause mismatches

Common Mistakes with SQL TRAILING

  • Omitting the FROM keyword: TRIM(TRAILING '0' '123') -- invalid
  • Expecting TRAILING to work outside TRIM (it does not)
  • Forgetting that default trim character is a space and wondering why other chars remain
  • Passing multi-character trim strings to engines that only allow single characters

Related Topics

First Introduced In

SQL:1999

Frequently Asked Questions

What does SQL TRAILING do?

TRAILING directs the TRIM function to remove characters only from the right side of a string.

Can I call TRAILING by itself?

No. TRAILING must appear inside TRIM; it is not a standalone function or clause.

What happens if I omit the trim character?

The database removes spaces by default.

Is TRAILING faster than BOTH or LEADING?

Performance is generally identical because all are parsed into the same underlying trimming operation by the engine.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!