{"record":{"id":"c542e51ac0660292","repo":"risingwavelabs/risingwave","slug":"column-unspecified-in-primary-key-mismatches-wi","errorCode":null,"errorMessage":"column {} unspecified in primary_key mismatches with the downstream SQL Server table {} PK","messagePattern":"column (.+?) unspecified 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":238,"sourceCode":"                }\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\n                .values()\n                .filter(|metadata| metadata.is_pk)\n                .map(|metadata| metadata.name.as_str())\n                .collect::<Vec<_>>()\n                .join(\",\");\n            let rw_pk_columns = self\n                .pk_indices","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/sqlserver.rs#L220-L256","documentation":"The mirror case of error 887: a column that is part of the downstream SQL Server table's PRIMARY KEY must also be declared in the RisingWave sink's primary_key. validate() raises this when a SQL Server PK column is not marked as RW PK (non-append-only sink).","triggerScenarios":"Non-append-only SQL Server sink whose declared primary_key omits one or more columns that are part of the downstream table's PRIMARY KEY.","commonSituations":"Downstream table has a composite PK (id, tenant_id) but the sink only declares PRIMARY KEY (id); defaulting to the MV's PK which differs from the table PK.","solutions":["Extend the sink's PRIMARY KEY clause to include all downstream PK columns","Alter the SQL Server table's PK to match the sink's primary_key columns","Switch to append_only sink type if upsert matching on the full PK is not required"],"exampleFix":"// before\nCREATE SINK ... PRIMARY KEY (id) ...; -- table PK is (id, tenant_id)\n// after\nCREATE SINK ... PRIMARY KEY (id, tenant_id) ...;","handlingStrategy":"validation","validationCode":"-- ensure every downstream PK column appears in the sink's PRIMARY KEY clause\nSELECT c.name FROM sys.key_constraints kc\nJOIN sys.index_columns ic 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');\n-- all returned names must be in the sink primary_key list","typeGuard":null,"tryCatchPattern":"match sink.validate().await {\n    Err(e) if e.to_string().contains(\"unspecified in primary_key mismatches\") => extend_sink_pk_and_recreate(),\n    other => other,\n}","preventionTips":["Include ALL downstream PK columns (including composite keys) in the sink's PRIMARY KEY","Generate sink definitions from downstream schema metadata","Document composite PKs so they are not partially declared"],"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"}