【问题标题】:How to Insert the same records in same table with different value under Id column? (Note : ID is primary key autoincrement column )如何在 Id 列下插入具有不同值的同一表中的相同记录? (注:ID是主键自增列)
【发布时间】:2019-04-10 12:04:14
【问题描述】:

假设我的表级别为

ID  name    abbr    countryid
1   None    NN  11
2   Middle  MD  33
3   Senior  SN  33
4   Junior  JN  22

不,我想将 countryid 33 的记录插入到 countryid 44 的同一张表中(Countryid 44 将是输入参数)。但是如何在列 ID 下插入数据?因为 Id 是自增?

INSERT INTO Master_LevelsGrades(Id, LevelName, LevelAbbr, CountryId)
(
select  ?? ,LevelName,LevelAbbr,@NewCountryId
 from Master_LevelsGrades where CountryId=33
)

【问题讨论】:

    标签: sql sql-server sql-server-2017-express


    【解决方案1】:

    别管它了:

    insert into Master_LevelsGrades (LevelName, LevelAbbr, CountryId)
        select  LevelName, LevelAbbr, @NewCountryId
        from Master_LevelsGrades
        where CountryId = 33;
    

    它将自动设置。

    【讨论】:

    • 嗨@BTSQL,欢迎来到stackoverflow!如果此答案是您问题的正确答案,则应将其标记为已接受,以便所有人都能立即看到,即使是在问题页面之外。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 2017-04-23
    • 2019-05-25
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多