Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • AI Helper
    • Team Sharing
    • Index Manager
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Blog
    • Community
    • Testimonials
    • Whitepapers
    • Reports
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Careers
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • Download
  • My 3T
search

AMA: Setting an SQL Migration primary key

Posted on: 14/11/2022 by Dj Walker-Morgan

Q: How do I set the primary key in a Studio 3T Migration from MongoDB to SQL? I want to set my own primary key field name and start it at a specific value.

Welcome to the latest Studio 3T Ask Manatees Anything – #Studio3T_AMA. Want to know how to use Studio 3T to make your MongoDB life better? Just tweet and use #Studio3T_AMA or email [email protected].

A: You can set your SQL primary key through the Migration Mappings interface. When you do an SQL Migration with Studio 3T you are able to configure a whole range of mapping operations that can split your data’s arrays and embedded documents across multiple tables. We added support for setting the migration’s primary key name and initial value in Studio 3T 2022.8. Don’t forget to upgrade!

Setting a migration’s primary key

At the top of the mapping tree will typically be the core table that you are migrating to. It’s here where you can set that table’s new primary key. Select edit on the table entry and you’ll see this dialog:

This is the main place for setting a primary key in a migration; it's the root mapping for the table

Because it represents the root document and how it maps to a table, there will not be a lot to set here. What you will see at the bottom though, is the Relationship section. It’s here where you can set the new Primary key name and its initial value. For this migration, we call the primary key customer_id here and start its value at 1000. Setting and applying that primary key reflects in the preview:

The change in mapping is reflected in the preview. See the initial value increment.

Beyond the main SQL table

Setting the primary key is not just for the root table. Where an object or array maps to another table, you can edit the primary key for that new table. For example, the address field in our collection maps to an address table. If we look up that table in the mappings we can see what it is creating to achieve this:

You can also set the primary key in migration on foreign key liked tables.

There’s more to be set here, as it handles the mapping of the data in the address field. Look down to the relationship section and you’ll see the options to set the primary key and its initial values. Again, we’ve set this to the more explanatory address_id and started it from 5000. In the preview, we’ll see that being applied:

The changes also show in the preview.

Wrapping up

As a result of the addition of primary key and value settings to Studio 3T 2022.8, it is now much easier to make much more readable and numerically separated ID fields when exporting to SQL.


How helpful was this article?
This article was hideous
This article was bad
This article was ok
This article was good
This article was great
Thank you for your feedback!

About The Author

Dj Walker-Morgan

Dj has been around since Commodore had Pets and Apples grew everywhere. With a background in Unix and development, he's been around the technology business writing code or writing content ever since.

Related articles

  • SQL Migration: MongoDB and SQL, Coexistence Made Easy
  • SQL Migration: MongoDB and SQL, Coexistence Made Easy
  • Moving from SQL to MongoDB? Studio 3T’s SQL Migration feature makes it simple
  • Quality Assurance Roles at 3T: Key Traits
  • AMA: How do I start sharing schemas with Studio 3T?

Tags

2022 academy aggregation AMA atlas Certification christmas community connections culture date tags events export features hackolade import intellishell In Use JSON knowledge base migration modelling mongodb mongoodb mongosh My 3T productivity product management query regex releases schema security SQL Studio 3T studio3t tasks time series tips updates webinar windows

Browse by MongoDB topic

  • Connecting to MongoDB
  • Database Administration & Security
  • Getting Started with MongoDB
  • Getting Started with Studio 3T
  • Import/Export
  • Job Automation & Scheduling
  • MongoDB Aggregation Framework
  • MongoDB/Studio 3T Workshops
  • Performance
  • Query & CRUD Operations
  • Reference
  • Schema
  • Studio 3T Licensing
  • Support and other resources
  • Working with MongoDB & SQL
  • Working with MongoDB Atlas

Studio 3T

MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

Education

  • Free MongoDB Tutorials
  • Connect to MongoDB
  • Connect to MongoDB Atlas
  • Import Data to MongoDB
  • Export MongoDB Data
  • Build Aggregation Queries
  • Query MongoDB with SQL
  • Migrate from SQL to MongoDB

Resources

  • Feedback and Support
  • Sales Support
  • Knowledge Base
  • FAQ
  • Reports
  • White Papers
  • Testimonials
  • Discounts

Company

  • About Us
  • Blog
  • Careers
  • Legal
  • Press
  • Privacy Policy
  • EULA

© 2023 3T Software Labs Ltd. All rights reserved.

  • Privacy Policy
  • Cookie settings
  • Impressum

We value your privacy

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data.

By clicking “Accept all”, you consent to the storage of cookies and the processing of personal data for these purposes, including any transfers to third countries. By clicking on “Decline all”, you do not give your consent and we will only store cookies that are necessary for our website. You can customize the cookies we store on your device or change your selection at any time - thus also revoking your consent with effect for the future - under “Manage Cookies”, or “Cookie Settings” at the bottom of the page. You can find further information in our Privacy Policy.
Accept all
Decline all
Manage cookies
✕

Privacy Preference Center

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in our Privacy Policy.

Accept all cookies

Manage consent preferences

Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

Google Analytics

Google Ads

Bing Ads

Facebook

LinkedIn

Quora

Hotjar

Reddit

Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

HubSpot

Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

Accept selected
✕