> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 从 NoSQL 迁移到 SQL

> 将 NoSQL 数据库迁移到 SQL 数据库，以提升数据一致性和关系完整性

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<div id="overview">
  ## 概览
</div>

Devin 可以帮助你将应用程序从 NoSQL 数据库迁移到 SQL，负责 schema 设计、数据转换以及查询重构。无论你是从 MongoDB 迁移到 PostgreSQL，还是从 DynamoDB 迁移到 MySQL，Devin 都可以系统化地转换你的数据模型、迁移数据，并更新应用代码，使其能够与关系型数据库配合使用。

<iframe width="840" height="473" src="https://www.youtube.com/embed/KiQJtRIWcK4" title="YouTube video player" className="max-w-full" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen />

<div id="why-migrate-to-sql">
  ## 为什么要迁移到 SQL？
</div>

<div id="data-integrity-benefits">
  ### 数据完整性优势
</div>

* **ACID 合规性**：通过事务确保数据一致性
* **参照完整性**：使用外键约束强制维护表之间的关系
* **模式验证**：在数据库层面阻止无效数据
* **复杂查询**：利用强大的 JOIN 操作和聚合能力

<div id="operational-advantages">
  ### 运营优势
</div>

* **成熟的工具链**：可利用数十年积累的 SQL 优化和监控工具
* **标准化**：在不同数据库中统一使用行业标准 SQL
* **更好的分析能力**：简化报表制作和商业智能集成
* **成本效益**：通过规范化和索引优化存储

<div id="common-migration-scenarios">
  ## 常见迁移场景
</div>

<div id="mongodb-to-postgresql">
  ### MongoDB 到 PostgreSQL
</div>

* 将文档集合转换为规范化表
* 将嵌入文档拆分为关联表
* 将 MongoDB 查询迁移为包含适当 JOIN 的 SQL
* 创建索引用于查询优化

<div id="dynamodb-to-mysql">
  ### DynamoDB 到 MySQL
</div>

* 将分区键（partition key）和排序键（sort key）映射为主键
* 将 NoSQL 访问模式转换为 SQL 查询
* 处理二级索引和全局表
* 将应用程序代码从 AWS SDK 迁移到 SQL 驱动程序

<div id="schema-design-and-normalization">
  ### 模式设计与规范化
</div>

* 分析 NoSQL 数据结构及其关系
* 按照最佳实践设计规范化的模式
* 创建包含数据校验的迁移脚本
* 设置适当的约束和索引

<div id="additional-resources">
  ## 其他资源
</div>

* [PostgreSQL 文档](https://www.postgresql.org/docs/)
* [MySQL 文档](https://dev.mysql.com/doc/)
* [Devin Playbooks](/zh/product-guides/creating-playbooks) - 创建可重复使用的迁移工作流
* [Devin Knowledge](/zh/product-guides/knowledge) - 存储各数据库特定的模式

<div id="related-use-cases">
  ## 相关用例
</div>

* [迁移与现代化](/zh/use-cases/migration-modernization)
* [数据分析](/zh/use-cases/data-analysis)
* [测试与重构](/zh/use-cases/testing-refactoring)
