如何轻松连接 Microsoft SQL Server 表?

发布于 2024-09-11 13:19:40 字数 221 浏览 3 评论 0原文

我有两个单独的表用于类别。

一个是Categories(ID, Title, Description),另一个是SubCategories(ID, UpperID, Title, Description)

我想将类别中的记录插入到子类别中上ID=0。我看过 SQL SELECT INTO 但不知道如何将它用于现有表。

I have two separate tables used for categories.

One is Categories(ID, Title, Description), and the other is SubCategories(ID, UpperID, Title, Description)

I want to insert the records from categories to SubCategories with upperID=0. I've looked at SQL SELECT INTO but don't know how to use it for existing tables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-09-18 13:19:40
Insert Into dbo.SubCategories (UpperId, Title, Description)

Select 0, Title, Description
From dbo.Categories

假设两个表中的 ID 列都是 Identity 列,并且 Category 中的 ID 不应传输到 SubCategories 表

Insert Into dbo.SubCategories (UpperId, Title, Description)

Select 0, Title, Description
From dbo.Categories

This assumes that the ID column in both tables is an Identity column and that the ID in Categories should not be transferred to the SubCategories table

谁人与我共长歌 2024-09-18 13:19:40
INSERT INTO SubCategories(ID, UpperID, Title, Description)

SELECT ID, 0, Title, Description FROM Categories

假设 Id 不是 Identity 字段。

INSERT INTO SubCategories(ID, UpperID, Title, Description)

SELECT ID, 0, Title, Description FROM Categories

assuming that Id is not Identity field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文