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:
Connect to your destination Cloud SQL instance with a SQL client. You
can use the following methods:
psql client. You can use this method to connect
to your instance private IP, but it might require that you create
a Compute Engine virtual machine.
gcloud sql connect command. This command
works only for Cloud SQL instances that have a public IP address
enabled.
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-08-29 UTC."],[[["\u003cp\u003eThis Database Migration Service feature facilitates heterogeneous migrations from SQL Server to Cloud SQL for PostgreSQL, but it is currently a Pre-GA offering with potential limitations in support and availability.\u003c/p\u003e\n"],["\u003cp\u003eThe service only migrates tables that include primary keys, necessitating manual creation of primary key constraints on tables lacking them after schema conversion.\u003c/p\u003e\n"],["\u003cp\u003eMigrating SQL Server tables without primary keys involves converting the schema, applying it to the destination database, connecting to the Cloud SQL instance, and adding the necessary primary key constraints.\u003c/p\u003e\n"],["\u003cp\u003ePrimary keys can be created using existing unique columns or, if necessary, by combining all columns in the table, ensuring the composite key does not exceed the maximum length allowed.\u003c/p\u003e\n"],["\u003cp\u003eAfter adding primary keys to all tables, the next step is to create a migration job to proceed with the migration, following the detailed migration guide available.\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-csql-pgsql/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-csql-pgsql/convert-sql).\n2. Connect to your destination Cloud SQL instance with a SQL client. You can use the following methods:\n - [`psql` client](/sql/docs/postgres/connect-admin-ip). You can use this method to connect to your instance private IP, but it might require that you create a Compute Engine virtual machine.\n - [`gcloud sql connect`](/sdk/gcloud/reference/sql/connect) command. This command works only for Cloud SQL instances that have a public IP address enabled.\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-csql-pgsql/create-migration-job).\n\n- To get a complete, step-by-step migration walkthrough, see\n [SQL Server to Cloud SQL for PostgreSQL migration guide](/database-migration/docs/sqlserver-to-csql-pgsql/guide)."]]