修改订单号数据类型4:复制订阅的主键限制 修改后
2012-05-18 15:07
429 查看
select db,sch,tbl,col,
--编写删除语句
'
use ['+publisher_db+']
exec sp_dropsubscription @publication = N'''+publication+''', @article = N'''+article+'''
, @subscriber = N''all'', @destination_db = N''all''
exec sp_droparticle @publication = N'''+publication+''', @article = N'''+source_object+''', @force_invalidate_snapshot = 1
' as dropscripts,
--编写生成语句
'
use ['+publisher_db+']
exec sp_addarticle @publication = N'''+publication+''', @article = N'''+article+''',
@source_owner = N'''+source_owner+''', @source_object = N'''+source_object+''', @type = N''logbased'',
@description = N'''', @creation_script = N'''', @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'''+
(case when exists(
select 1 from sys.all_columns t1
inner join sys.index_columns t2 on t1.object_id=t2.object_id and t1.column_id=t2.column_id
inner join sys.indexes t3 on t3.object_id=t2.object_id and t3.index_id=t2.index_id
and t1.is_identity=1 and t3.is_primary_key=1
where t1.object_id=object_id(quotename(aa.source_owner)+'.'+quotename(aa.source_object)) )
then 'manual' else 'none' end)
+''', @destination_table = N'''+destination_object+'''
, @destination_owner = N'''+isnull(destination_owner,source_owner)+''', @status = 24,
@vertical_partition = N''false'', @ins_cmd = N''CALL [dbo].[sp_MSins_dbo'+source_object+']''
, @del_cmd = N''CALL [dbo].[sp_MSdel_dbo'+source_object+']'',
@upd_cmd = N''SCALL [dbo].[sp_MSupd_dbo'+source_object+']''
' as addscripts
from
(
--查询复制订阅项目信息
SELECT a.article,a.publisher_db,b.publication,a.source_owner,a.source_object,a.destination_object,a.destination_owner,
s.db,s.sch,s.tbl,s.col
FROM [distribution].[dbo].[MSarticles] a inner join
[distribution].[dbo].[MSpublications] b
on a.publication_id=b.publication_id
inner join
(
--查询主键信息
select distinct db_name() as db, c.name sch,sp.name tbl,sc.name col from dbo.sysindexes si INNER JOIN
dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid INNER JOIN
dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid INNER JOIN
dbo.sysobjects so ON so.name = si.name AND so.xtype = 'PK'
inner join sys.sysobjects sp on so.parent_obj=sp.id
inner join sys.schemas c on c.schema_id=sp.uid
intersect
--查询定义好的信息做交集
select db,sch,tbl,col from master.dbo.UnionALL
) s
on a.publisher_db=s.db and a.source_owner=s.sch and a.source_object=s.tbl)
aa
--select * from sys.all_columns a
--inner join sys.index_columns b on a.object_id=b.object_id and a.column_id=b.column_id
--inner join sys.indexes c on b.object_id=c.object_id and b.index_id=c.index_id
--and a.is_identity=1 and c.is_primary_key=1
--where a.object_id=object_id('OrderFlow.BackChangeApply')
--(case when exists(
--select 1 from sys.all_columns a
--inner join sys.index_columns b on a.object_id=b.object_id and a.column_id=b.column_id
--inner join sys.indexes c on b.object_id=c.object_id and b.index_id=c.index_id
--and a.is_identity=1 and c.is_primary_key=1
--where a.object_id=object_id(quotename(a.source_owner)+'.'+quotename(a.source_object))
--then '' else '' end)
--编写删除语句
'
use ['+publisher_db+']
exec sp_dropsubscription @publication = N'''+publication+''', @article = N'''+article+'''
, @subscriber = N''all'', @destination_db = N''all''
exec sp_droparticle @publication = N'''+publication+''', @article = N'''+source_object+''', @force_invalidate_snapshot = 1
' as dropscripts,
--编写生成语句
'
use ['+publisher_db+']
exec sp_addarticle @publication = N'''+publication+''', @article = N'''+article+''',
@source_owner = N'''+source_owner+''', @source_object = N'''+source_object+''', @type = N''logbased'',
@description = N'''', @creation_script = N'''', @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'''+
(case when exists(
select 1 from sys.all_columns t1
inner join sys.index_columns t2 on t1.object_id=t2.object_id and t1.column_id=t2.column_id
inner join sys.indexes t3 on t3.object_id=t2.object_id and t3.index_id=t2.index_id
and t1.is_identity=1 and t3.is_primary_key=1
where t1.object_id=object_id(quotename(aa.source_owner)+'.'+quotename(aa.source_object)) )
then 'manual' else 'none' end)
+''', @destination_table = N'''+destination_object+'''
, @destination_owner = N'''+isnull(destination_owner,source_owner)+''', @status = 24,
@vertical_partition = N''false'', @ins_cmd = N''CALL [dbo].[sp_MSins_dbo'+source_object+']''
, @del_cmd = N''CALL [dbo].[sp_MSdel_dbo'+source_object+']'',
@upd_cmd = N''SCALL [dbo].[sp_MSupd_dbo'+source_object+']''
' as addscripts
from
(
--查询复制订阅项目信息
SELECT a.article,a.publisher_db,b.publication,a.source_owner,a.source_object,a.destination_object,a.destination_owner,
s.db,s.sch,s.tbl,s.col
FROM [distribution].[dbo].[MSarticles] a inner join
[distribution].[dbo].[MSpublications] b
on a.publication_id=b.publication_id
inner join
(
--查询主键信息
select distinct db_name() as db, c.name sch,sp.name tbl,sc.name col from dbo.sysindexes si INNER JOIN
dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid INNER JOIN
dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid INNER JOIN
dbo.sysobjects so ON so.name = si.name AND so.xtype = 'PK'
inner join sys.sysobjects sp on so.parent_obj=sp.id
inner join sys.schemas c on c.schema_id=sp.uid
intersect
--查询定义好的信息做交集
select db,sch,tbl,col from master.dbo.UnionALL
) s
on a.publisher_db=s.db and a.source_owner=s.sch and a.source_object=s.tbl)
aa
--select * from sys.all_columns a
--inner join sys.index_columns b on a.object_id=b.object_id and a.column_id=b.column_id
--inner join sys.indexes c on b.object_id=c.object_id and b.index_id=c.index_id
--and a.is_identity=1 and c.is_primary_key=1
--where a.object_id=object_id('OrderFlow.BackChangeApply')
--(case when exists(
--select 1 from sys.all_columns a
--inner join sys.index_columns b on a.object_id=b.object_id and a.column_id=b.column_id
--inner join sys.indexes c on b.object_id=c.object_id and b.index_id=c.index_id
--and a.is_identity=1 and c.is_primary_key=1
--where a.object_id=object_id(quotename(a.source_owner)+'.'+quotename(a.source_object))
--then '' else '' end)
相关文章推荐
- 订单号数据类型修改--删除和创建复制订阅项目(只需要操作指定字段作为主键的那些)
- mysql笔记4 - SQL函数(聚合函数,标量函数(大小写,长度),mid函数(显示形式),as别名,union,add,drop,修改表中某列的数据类型,主键限制,外键限制,非空限制,trunca
- 修改表主键字段数据类型(up_ModifyPrimaryColumn)
- 修改表主键字段数据类型(up_ModifyPrimaryColumn)
- 修改Oracle数据库表的主键对应列的数据类型
- Mysql复制表结构、表数据以及修改主键
- mysql数据库 text类型的长度限制,使用change_column来进行长度的修改并不影响原有数据
- 修改订单号数据类型代码
- 修改数据类型+增加列+修改列名+设置主键+设置键值默认值+sys_guid函数
- oracle处理已有数据的字段(主键)类型修改方法
- sql server 2005 中数据库表 的创建 ,查看表 属性,表的名称重命名,情况表中信息,删除表 ; 表中列重命名,添加新列,修改列的数据类型,删除列,设置列的主键外键
- 获取mssqlserver数据库表的字段名称,字段说明,数据类型,主键等表的信息
- oracle修改表已存列的数据类型与列名重命名
- js中的5种数据类型进行值复制
- js基本数据类型引用类型深复制浅复制
- SAP中关于物料主数据里物料类型的修改
- 利用sqlite创建一个数据user,其含有一张表person,该person表中含有三个列,其中第一字段为主键int类型的,其他两个字段自定义数据类型和名称。
- 解决Ext Combobox允许用户插入及修改任意值,不用限制只能新增或修改数据表里即有字段
- GUID和INT两种数据类型做主键的比较
- 使用Nhibernate修改实体主键并保存数据