Stay organized with collections
Save and categorize content based on your preferences.
Database Migration Service migrates only tables that have primary keys.
If your source database includes tables that don't have primary keys,
you need to manually create primary key constraints in the converted tables
in the destination database after you
apply the converted schema.
To migrate SQL Server tables without primary keys, do the following:
Create the missing primary key constraints for your tables. For more
information about primary keys, see
Primary Keys in the PostgreSQL documentation.
You can also expand the following sections to see sample SQL commands:
Create primary keys using existing columns
Your table might already have a logical primary key based on a
column or a combination of columns. For example, there might be
columns with a unique constraint or index configured. Use these
columns to generate a new primary key for tables in your source
database. For example:
ALTERTABLETABLE_NAMEADDPRIMARYKEY(COLUMN_NAME);
Create a primary key using all columns
If you don't have a pre-existing constraint that could serve as a
primary key, create primary keys using all columns of the table. Make
sure that you don't exceed the maximum length of the primary key
allowed by your PostgreSQL instance. For example:
When creating a composite primary key like this, you need to explicitly
list all column names you want to use. It's not possible to use a statement
to retrieve all column names for this purpose.
What's next
Once all your converted tables have primary key constraints, you can
proceed with your migration and
create a migration job.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eDatabase Migration Service only migrates tables with primary keys during heterogeneous SQL Server to AlloyDB for PostgreSQL migrations.\u003c/p\u003e\n"],["\u003cp\u003eTables without primary keys in the source SQL Server database will require manual creation of primary key constraints in the destination AlloyDB database.\u003c/p\u003e\n"],["\u003cp\u003eYou can create primary keys by using existing columns with unique constraints or indexes.\u003c/p\u003e\n"],["\u003cp\u003eIf no suitable columns exist, a primary key can be created using all columns of the table, provided the maximum length limit of the primary key is not exceeded.\u003c/p\u003e\n"],["\u003cp\u003eOnce all the converted tables have primary key constraints, the user can proceed to create a migration job.\u003c/p\u003e\n"]]],[],null,["# Migrate tables without primary keys\n\nDatabase Migration Service migrates only tables that have primary keys.\nIf your source database includes tables that don't have primary keys,\nyou need to manually create primary key constraints in the converted tables\nin the destination database after you\n[apply the converted schema](/database-migration/docs/sqlserver-to-alloydb/work-with-conversion-workspaces#apply-to-dest).\n\nTo migrate SQL Server tables without primary keys, do the following:\n\n1. [Convert all your schema and apply it to the destination database](/database-migration/docs/sqlserver-to-alloydb/convert-sql).\n2. [Connect to your AlloyDB for PostgreSQL instance with the `psql` client](/alloydb/docs/connect-psql).\n3. Create the missing primary key constraints for your tables. For more information about primary keys, see [Primary Keys](https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-PRIMARY-KEYS) in the PostgreSQL documentation.\n\n You can also expand the following sections to see sample SQL commands: \n\n #### Create primary keys using existing columns\n\n Your table might already have a logical primary key based on a\n column or a combination of columns. For example, there might be\n columns with a unique constraint or index configured. Use these\n columns to generate a new primary key for tables in your source\n database. For example: \n\n ```sql\n ALTER TABLE TABLE_NAME\n ADD PRIMARY KEY (COLUMN_NAME);\n ```\n\n \u003cbr /\u003e\n\n #### Create a primary key using all columns\n\n If you don't have a pre-existing constraint that could serve as a\n primary key, create primary keys using all columns of the table. Make\n sure that you don't exceed the maximum length of the primary key\n allowed by your PostgreSQL instance. For example: \n\n ```sql\n ALTER TABLE TABLE_NAME\n ADD PRIMARY KEY (COLUMN_NAME_1, COLUMN_NAME_2, COLUMN_NAME_3, ...);\n ```\n\n When creating a composite primary key like this, you need to explicitly\n list all column names you want to use. It's not possible to use a statement\n to retrieve all column names for this purpose.\n\nWhat's next\n-----------\n\n- Once all your converted tables have primary key constraints, you can\n proceed with your migration and\n [create a migration job](/database-migration/docs/sqlserver-to-alloydb/create-migration-job).\n\n- To get a complete, step-by-step migration walkthrough, see\n [SQL Server to AlloyDB for PostgreSQL migration guide](/database-migration/docs/sqlserver-to-alloydb/guide)."]]