简体   繁体   English

如何在ID列下的同一表中插入具有不同值的相同记录? (注意:ID是主键自动递增列)

[英]How to Insert the same records in same table with different value under Id column? (Note : ID is primary key autoincrement column )

Suppose i have table level as 假设我的表级别为

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

No i want to insert the records of countryid 33 in same table with countryid 44 (Countryid 44 will be input parameter).But how to insert data under column ID? 不,我想将countryid 33的记录插入与countryid 44相同的表中(Countryid 44将作为输入参数)。但是如何在列ID下插入数据? as Id is autoincrement? 因为ID是自动递增的?

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

Just leave it out: 只需将其删除:

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

It will be set automagically. 它将自动设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将一列id(主键)插入不同的表? - How to insert one column id (which is primary key) to different table? 如何在多主键表中插入具有自动递增ID的行? - How to insert a row with autoincrement id in a multi-primary-key table? 查询获取同表中customerID列的每个唯一值的表的最大主键ID - Query to obtain the maximum primary key ID of a table for each unique value of the customerID column in the same table 如何将自动生成的主键ID保存在同一表的外键列中 - How to save auto generated primary key Id in foreign key column in same table 将具有相同列值的特定数量的记录插入到另一个表中 - Insert specific number of records with same column value into a different table 如何从同一个表中返回另一个列 id 的记录? - How to return records by another column id from same table? 如何在同一个表中显示具有相同列不同 id 的 2 个值 - How to show 2 value with same column different id in same tables 从SQL插入查询中获取新记录主键ID以将相同值插入另一个表中? - Get the new record primary key ID from SQL insert query to insert same value into another table? 从同一张表中获取来自不同ID的一列的值 - Get from the same table the value of one column from different ID 返回具有相同主键但在另一列中具有不同值的记录 - returning records with same primary key but different values in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM