当前位置:网站首页>Autoincrement attribute of sqlserver replication table
Autoincrement attribute of sqlserver replication table
2022-06-22 23:14:00 【Tangsanshui】
because Navicat Start paying to use , Just change it to dbEaver, But the strange thing about this tool is
Export After data table backup The primary key will be lost , If you directly create a table and import related data , Auto increment settings and other special configurations
Scheme 1 : Directly based on the existing id( Imported table without auto increment attribute ) Add a new self increasing attribute
alter table aaa drop column id
alter table aaa add id int identity(1,1)
The problem is , Menus in the system Permissions and other related data ,id Must be in three environments test\uat\pro Is consistent in the database , The above method will lead to Table of three libraries id The value of is increased in order , It may not be consistent with the original data , If there is... In the original data id The row data of has been deleted , That must be the new self increase id It's not the same ,
If you have a requirement to keep the self increasing attribute consistent , Then scheme 2 must be more suitable .
Option two : Can keep id The original value of is consistent with the source table , And the next self increment is consistent
1、Export table Data source table —— Only basic data ;
2、 Create new table Yes identity Properties of ;
-- Another way Create a new table first Reimport data
DROP TABLE basf_filte_keyword;
CREATE TABLE basf_filter_keyword (
id int IDENTITY(1,1) NOT NULL primary key,
keyword nvarchar(255) COLLATE Chinese_PRC_CI_AI NULL,
translation_en nvarchar(255) COLLATE Chinese_PRC_CI_AI NULL,
translation_jp nvarchar(255) COLLATE Chinese_PRC_CI_AI NULL,
create_time int NULL,
status tinyint NULL,
update_time int NULL,
create_by int NULL,
update_by int NULL
);
3、 Import relevant data from the target table
-- Cancel the self increasing of the sequence SQL sentence
set identity_insert basf_resource on
insert into basf_resource (name, sort, parent_id, resource_type, url, resource_code, data_status, icon, update_date, create_date, id,function_type, name_zh, resource_module, name_jp)
select name, sort, parent_id, resource_type, url, resource_code, data_status, icon, update_date, create_date, id1, function_type, name_zh, resource_module, name_jp from basf_resource_pro_20220621 brp ;
set identity_insert basf_resource off
Other small methods related to self increasing attributes :
-- Query auto increment of current table id
SELECT IDENT_CURRENT('basf_resource ');
-- Reset the maximum auto increment of the current table id
dbcc checkident('basf_resource ',reseed,694);
hope dbEaver Better and better , You can copy and paste the corresponding primary key and auto increment attribute , If you have a better way to solve this problem , Welcome to leave a message
边栏推荐
- R language data preprocessing, converting type variables into factor variables, converting data sets into H2O format, and dividing data sets (training set, test set, verification set)
- Core and semiconductor "RF eda/ filter design platform" shines ims2022
- 2020-12-20
- Next permutation [give play to subjective initiative to discover laws]
- 2020-12-04
- Do domestic mobile phones turn apples? It turned out that it was realized by 100 yuan machine and sharp price reduction
- 获取当前所在周的起始和结束的日期
- Zynq ultrascale + rfsoc zcu111 RF clock tree learning 1
- Mysql8 installation and environment configuration
- 2021-08-21
猜你喜欢

2021-08-26

China Mobile's mobile phone users grow slowly, but strive for high profit 5g package users

MySQL master-slave synchronization and its basic process of database and table division

Core and semiconductor "RF eda/ filter design platform" shines ims2022

2021-04-16

Remote access and control - SSH Remote Management and TCP wrappers access control

Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization

保证数据库和缓存的一致性
Solution to cache inconsistency

Spark RDD Programming Guide(2.4.3)
随机推荐
获取当前所在周的起始和结束的日期
SourceTree版本管理常用操作
Case 2 of SQL performance degradation caused by modifying implicit parameters
Spark RDD Programming Guide(2.4.3)
Atcoder abc256 full problem solution (interval merging template, matrix fast power optimization DP, line segment tree...)
2021-04-16
MySQL constraints
Basic MySQL database operations
Phantomjs utility code snippet (under continuous update...)
Is it bad for NFT that the market starts to cool down?
The relationship between derivative and differential of function
R language data preprocessing, converting type variables into factor variables, converting data sets into H2O format, and dividing data sets (training set, test set, verification set)
mysql主从同步及其分库分表基本流程
2021-08-26
Several ways of redis persistence -- deeply parsing RDB
SSH method 2 for adding node nodes in Jenkins
对 cookie 的添加/获取和删除
The mental process and understanding of visual project code design
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
2021-08-21