Skip to content

SQLServer Writer

SQLServer Writer plugin implements the functionality of writing data to SQL Server database tables.

Configuration Example

Here we use data generated from memory to import into SQL Server.

json
{
  "job": {
    "setting": {
      "speed": {
        "channel": 1,
        "bytes": -1
      }
    },
    "content": {
      "reader": {},
      "writer": {
        "name": "sqlserverwriter",
        "parameter": {
          "username": "root",
          "password": "root",
          "column": [
            "db_id",
            "db_type",
            "db_ip",
            "db_port",
            "db_role",
            "db_name",
            "db_username",
            "db_password",
            "db_modify_time",
            "db_modify_user",
            "db_description",
            "db_tddl_info"
          ],
          "preSql": [
            "delete from @table where db_id = -1;"
          ],
          "postSql": [
            "update @table set db_modify_time = now() where db_id = 1;"
          ],
          "connection": {
            "table": [
              "db_info_for_writer"
            ],
            "jdbcUrl": "jdbc:sqlserver://[HOST_NAME]:PORT;DatabaseName=[DATABASE_NAME]"
          }
        }
      }
    }
  }
}

Parameters

This plugin is based on RDBMS Writer, so you can refer to all configuration items of RDBMS Writer.

writeMode

By default, insert into syntax is used to write to SQL Server tables. If you want to use the mode of updating when primary key exists and inserting when it doesn't exist, which is SQL Server's MERGE INTO syntax, you can use update mode. Assuming the table's primary key is id, the writeMode configuration method is as follows:

json
{
  "writeMode": "update(id)"
}

If it's a composite unique index, the configuration method is as follows:

json
{
  "writeMode": "update(col1, col2)"
}