{"record":{"id":"c3888b7ad1d095cf","repo":"risingwavelabs/risingwave","slug":"column-specified-in-primary-key-mismatches-with","errorCode":null,"errorMessage":"column {} specified in primary_key mismatches with the downstream SQL Server table {} PK","messagePattern":"column (.+?) specified in primary_key mismatches with the downstream SQL Server table (.+?) PK","errorType":"validation","errorClass":"SinkError::SqlServer","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/sqlserver.rs","lineNumber":231,"sourceCode":"            match sql_server_table_metadata.get(&normalize_sql_server_column_name(&col.name)) {\n                None => {\n                    return Err(SinkError::SqlServer(anyhow!(format!(\n                        \"column {} not found in the downstream SQL Server table {}\",\n                        col.name,\n                        self.config.full_object_path()\n                    ))));\n                }\n                Some(sql_server_col) => {\n                    validate_data_type_compatibility(\n                        &col.name,\n                        &col.data_type,\n                        &sql_server_col.data_type,\n                    )?;\n                    if self.is_append_only {\n                        continue;\n                    }\n                    if rw_is_pk && !sql_server_col.is_pk {\n                        return Err(SinkError::SqlServer(anyhow!(format!(\n                            \"column {} specified in primary_key mismatches with the downstream SQL Server table {} PK\",\n                            col.name,\n                            self.config.full_object_path(),\n                        ))));\n                    }\n                    if !rw_is_pk && sql_server_col.is_pk {\n                        return Err(SinkError::SqlServer(anyhow!(format!(\n                            \"column {} unspecified in primary_key mismatches with the downstream SQL Server table {} PK\",\n                            col.name,\n                            self.config.full_object_path(),\n                        ))));\n                    }\n                }\n            }\n        }\n\n        if !self.is_append_only && sql_server_pk_count != self.pk_indices.len() {\n            let sql_server_pk_columns = sql_server_table_metadata","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/sqlserver.rs#L213-L249","documentation":"For non-append-only sinks, every RisingWave primary-key column must also be a primary key column in the downstream SQL Server table. validate() raises this error when a sink column is marked as RW PK but the corresponding SQL Server column is not part of the table's PK.","triggerScenarios":"CREATE SINK with `primary_key(col)` where `col` exists in the SQL Server table but is not part of that table's PRIMARY KEY constraint (and the sink is not append-only).","commonSituations":"SQL Server table created without PK or with a different PK than the one specified in RisingWave; changing the sink's primary_key after the downstream table exists.","solutions":["Recreate/alter the SQL Server table so its PRIMARY KEY matches the sink's primary_key columns","Change the sink's PRIMARY KEY to match the downstream table's actual PK columns","Make the sink append_only if upsert semantics are not needed"],"exampleFix":"// before\nCREATE SINK ... PRIMARY KEY (id) ...; -- SQL Server PK is (order_id)\n// after\nCREATE SINK ... PRIMARY KEY (order_id) ...; -- matches downstream PK","handlingStrategy":"validation","validationCode":"-- list downstream PK columns and confirm they equal the sink's primary_key\nSELECT c.name FROM sys.index_columns ic\nJOIN sys.key_constraints kc ON ic.object_id = kc.parent_object_id AND ic.index_id = kc.unique_index_id\nJOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id\nWHERE kc.type_desc = 'PRIMARY_KEY' AND kc.parent_object_id = OBJECT_ID('target');","typeGuard":null,"tryCatchPattern":"match sink.validate().await {\n    Err(e) if e.to_string().contains(\"specified in primary_key mismatches\") => align_pk_with_downstream(),\n    other => other,\n}","preventionTips":["Create the SQL Server table PK to exactly mirror the sink's primary_key","Never change one side's PK without the other","Inspect downstream PK metadata before authoring the sink"],"tags":["sqlserver","sink","primary-key","schema-mismatch"],"backgroundTag":"schema-validation-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}