修改訂單號資料型別4 複製訂閱的主鍵限制 修改後

2021-06-06 13:53:53 字數 3226 閱讀 6535

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--(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學號資料型別 資料庫常見資料型別和約束

常用資料型別 在這裡就列舉一些我們常用的資料型別 1 數值型 表示整數型資料型別 tinyint smallint mediumint int 浮點型資料型別 float double 用法 1 整形 學號 區別為儲存大小不同,取值範圍不同 tinyint m 取值 128,127 tinyint ...

有符號和無符號資料型別

原版出處 c語言中提供了很多整數型別 整型 主要區別在於它們取值範圍的大小。int代表有符號的整數,也就是說,用int宣告的變數可以是正數也可以是負數,也可以是零,但是只能是整數。比如 int a 3 int b 0 int c 5 以上這些都是合法的。int的取值範圍因機器而異,一般而言,在較舊的...

修改字段資料型別

我們假設相關表中沒有資料,使用sql語句修改字段型別的相關操作,以下就是具體方案的描述。如果表中沒有資料 直接這樣就可以了 alter table 表名 modify 欄位名 型別 eg alter table student id number 4 如果原表中存在data那麼方法就大不相同了,請看...