Home >Database >Mysql Tutorial >How to Insert Line Breaks in SQL Server VARCHAR/NVARCHAR Strings?
Insert newline character in SQL Server VARCHAR/NVARCHAR string
In SQL Server, inserting newlines into VARCHAR or NVARCHAR strings is often a necessary step to format text or create multi-line content. You can easily achieve this in SQL queries by using special characters.
The character combination of line break
There are several ways to create newlines in VARCHAR/NVARCHAR strings. The most common combinations are carriage return (CR) and line feed (LF), represented by CHAR(13) and CHAR(10) respectively. When combined, these two characters create a Windows-style line break.
For example, to insert a line break between two lines of text:
<code class="language-sql">'这是第一行。' + CHAR(13) + CHAR(10) + '这是第二行。'</code>
Other notes
If you prefer to use a single character to represent the newline character, you can also use CHAR(13), which only represents the CR character. This may be useful in some cases, but be aware that it creates a non-standard newline character that may not be compatible with all systems.
The above is the detailed content of How to Insert Line Breaks in SQL Server VARCHAR/NVARCHAR Strings?. For more information, please follow other related articles on the PHP Chinese website!