Databases 15 min read

Testing T‑SQL Compatibility in KingbaseES: Key Findings and Tips

This article walks through installing KingbaseES's SQL Server compatible edition, evaluates core T‑SQL features such as GO, PRINT, RAISERROR, THROW, statement terminators, and trailing commas in CREATE TABLE, provides practical code examples, and offers solutions to common Windows installation errors.

Wukong Talks Architecture
Wukong Talks Architecture
Wukong Talks Architecture
Testing T‑SQL Compatibility in KingbaseES: Key Findings and Tips

Introduction

Hello, I am Wukong, honored to serve as a product experience officer for Kingbase database. This article introduces the basic testing of the KingbaseES SQL Server compatible version's T‑SQL support.

1. Test Overview

KingbaseES has achieved high compatibility with SQL Server in special data types, objects, statements, T‑SQL syntax, and stored procedure calls. The following common T‑SQL constructs are tested:

Batch statement GO

PRINT statement

RAISERROR statement

THROW statement

Statement terminators (semicolon and comma)

2. Download and Install KingbaseES SQL Server Compatible Edition

Download Link

https://www.kingbase.com.cn/download.html

download page
download page

The version adds support for several SQL Server system views and built‑in functions, ICU library optimizations, advanced query features (FOR XML, PIVOT, GROUP BY with different data types, DISTINCT with ORDER BY aliases), DML‑triggered statistics updates, temporary table optimizations, and .Net driver enhancements for date functions.

Download Authorization File

The KingbaseES SQL Server compatible edition authorization file is valid for 90 days from the first database start.

authorization
authorization

3. Compatibility Tests

3.1 Batch Statements (GO)

Meaning

Batch statements combine multiple T‑SQL statements into a single execution unit. SQL Server separates statements with a semicolon (;) or the GO keyword.

Syntax

Using semicolon

SELECT * FROM Table1;
SELECT * FROM Table2;

Using GO

SELECT * FROM Table1;
GO
SELECT * FROM Table2;
GO

Notes

Semicolon : Required as a statement terminator in many contexts (e.g., TRY…CATCH, BEGIN…END).

GO keyword : Not part of T‑SQL syntax; it is a batch separator used by SSMS and sqlcmd and cannot be used inside stored procedures or functions.

Performance : Batching reduces network round‑trips, improving performance.

Practical Example

Example 1: Using semicolon

SELECT * FROM Table1;
SELECT * FROM Table2;
example semicolon
example semicolon

Example 2: Using GO

SELECT * FROM Table1;
GO
SELECT * FROM Table2;
GO
example GO
example GO

3.2 PRINT Statement

Meaning

The PRINT statement outputs text to the SQL Server message window, useful for debugging and logging.

Syntax

PRINT 'message';

Notes

Output limit : Maximum 8000 characters.

Performance : PRINT does not affect query execution, but excessive use may impact performance.

Debugging tools : In production, prefer using ERRORLOG or custom log tables.

Practical Example

Example 1: Print constant string

PRINT 'Hello, World!';
print constant
print constant

Example 2: Print variable value

DECLARE @Message NVARCHAR(100) = 'This is a test message.';
PRINT @Message;
print variable
print variable

3.3 RAISERROR Statement

Meaning

RAISERROR generates an error message and transfers control to a CATCH block (if present). It is commonly used for custom error handling.

Syntax

RAISERROR ( { msg_id | msg_str } , severity , state [ , argument [ ,...n ] ] );

Notes

Severity : Levels 11‑19 trigger CATCH blocks.

Performance : RAISERROR aborts the current execution flow; use sparingly.

Replacement : For SQL Server 2012+ use THROW instead of RAISERROR.

Practical Example

BEGIN TRY
    RAISERROR ('This is a custom error message.', 16, 1);
END TRY
BEGIN CATCH
    PRINT 'Error caught: ' + ERROR_MESSAGE();
END CATCH;
raiserror example
raiserror example

3.4 THROW Statement

Meaning

THROW throws an error and transfers control to a CATCH block, serving as a simpler alternative to RAISERROR.

Syntax

THROW [error_number , message , state];

Notes

Compatibility : Available only in SQL Server 2012 and later.

Performance : Like RAISERROR, it aborts the current execution flow.

Use case : Prefer THROW for custom errors in newer SQL Server versions.

Practical Example

BEGIN TRY
    THROW 50001, 'This is a custom error message.', 1;
END TRY
BEGIN CATCH
    PRINT 'Error caught: ' + ERROR_MESSAGE();
END CATCH;
throw example
throw example

3.5 Semicolon Requirement

Meaning

In SQL Server, the semicolon (;) marks the end of a statement.

Test

BEGIN TRY
    SELECT * FROM Table1
    SELECT * FROM Table2
END TRY
BEGIN CATCH
    PRINT 'Error occurred';
END CATCH;
semicolon test
semicolon test

3.6 Trailing Comma in CREATE TABLE

Meaning

SQL Server allows a trailing comma after the last column definition, which can simplify code maintenance.

Syntax

With trailing comma

CREATE TABLE ExampleTable (
    ID INT PRIMARY KEY,
    Data NVARCHAR(100),
    RowVer ROWVERSION,
);

Without trailing comma

CREATE TABLE ExampleTable (
    ID INT PRIMARY KEY,
    Data NVARCHAR(100),
    RowVer ROWVERSION
);

Notes

Trailing commas are accepted by SQL Server but not by some other DBMS such as MySQL.

Consistent style across a team improves maintainability.

Performance is unaffected.

Practical Example with Trailing Comma

CREATE TABLE ExampleTable (
    ID INT PRIMARY KEY,
    Data NVARCHAR(100),
    RowVer ROWVERSION,
);
trailing comma example
trailing comma example

Practical Example without Trailing Comma

CREATE TABLE ExampleTable (
    ID INT PRIMARY KEY,
    Data NVARCHAR(100),
    RowVer ROWVERSION
);
no trailing comma example
no trailing comma example

Summary of Tool Statements

Batch statements : Combine multiple T‑SQL statements to improve execution efficiency. PRINT statement : Useful for debugging and outputting information, but not recommended for production. RAISERROR statement : Custom error handling; for SQL Server 2012+ use THROW instead. THROW statement : Simpler syntax, replaces RAISERROR in newer versions.

These tool statements are valuable for SQL Server development and debugging; proper use enhances code readability and maintainability.

5. Windows Installation Error Summary

1. Initialization Failure

Solution

Disable 360 security software before proceeding.

2. Service Cannot Start

Open services.msc, locate the executable path.

services path
services path
cd D:\Program Files\Kingbase\ES\V9\KESRealPro\V009R004C012\Server\bin
./sys_ctl.exe runservice -N "kingbase9_R1_instance" -D "D:\Program Files\Kingbase\ES\V9\data" -w

sys_ctl: could not start service "kingbase9_R1_instance": error code 1063

./sys_ctl.exe -D "kingbase9_R1_instance" -D "D:\Program Files\Kingbase\ES\V9\data" start

waiting for server to start.....
HKT [18240] LOG:  正在启动 KingbaseES V009R004C012
HKT [18240] LOG:  正在监听IPv6地址 "::", 端口 54321
HKT [18240] LOG:  无法绑定IPv4地址 "0.0.0.0": Only one usage of each socket address (protocol/network address/port) is normally permitted.

HKT [18240] HINT:  端口54321上是否已经运行了另一个kingbase?如果没有,请等待几秒钟后重试。
HKT [18240] FATAL:  无法为 "*" 创建监听套接字
HKT [18240] LOG:  database system is shut down
stopped waiting
sys_ctl: could not start server
Examine the log output.

Solution

Option 1: Check if the port is occupied and kill the process.

netstat -ano | grep "54321"
kill <process id>

Option 2: Change the startup port.

D:\Program Files\Kingbase\ES\V9\data
port=54325

After restarting, the service starts successfully.

service started
service started

Verify the process and adjust the connection port to 54325.

connection success
connection success

3. Database Connection Error (Garbage Characters)

Solution

Select UTF‑8 encoding during installation.

SQLDatabase testingT-SQLKingbaseESSQL Server compatibility
Wukong Talks Architecture
Written by

Wukong Talks Architecture

Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.