久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用于刪除具有系統(tǒng)生成名稱的 PK 約束的 SQL Serv

SQL Server 2008 Script to Drop PK Constraint that has a System Generated Name(用于刪除具有系統(tǒng)生成名稱的 PK 約束的 SQL Server 2008 腳本)
本文介紹了用于刪除具有系統(tǒng)生成名稱的 PK 約束的 SQL Server 2008 腳本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試向 SQL Server 2008 中的現(xiàn)有表添加聚集索引,它需要是一個自動化腳本,因為該表存在于跨多個服務(wù)器的多個數(shù)據(jù)庫中.

I am trying to add a clustered index to an existing table in SQL Server 2008, and it needs to be an automated script, because this table exists on several databases across several servers.

為了添加聚集索引,我需要刪除表上的 PK 約束,然后將其重新添加為非聚集索引.問題是 PK 約束的名稱是自動生成的,并且在末尾附加了一個 guid,因此類似于PK_[Table]_D9F9203400".

In order to add a clustered index I need to remove the PK constraint on the table, and then re-add it as unclustered. The problem is the name of the PK constraint is auto-generated, and there is a guid appended to the end, so it's like "PK_[Table]_D9F9203400."

所有數(shù)據(jù)庫的名稱都不同,我不知道如何編寫一個自動化腳本,在我不知道約束名稱的表上刪除 PK 約束.任何幫助表示贊賞!

The name is different across all databases, and I'm not sure how to write an automated script that drops a PK constraint on a table in which I don't know the name of the constraint. Any help is appreciated!

更新:

下面的答案是我用過的.完整腳本:

Answer below is what I used. Full script:

Declare @Val varchar(100)
Declare @Cmd varchar(1000)

Set @Val = (
    select name
    from sysobjects
    where xtype = 'PK'
    and parent_obj = (object_id('[Schema].[Table]'))
)
Set @Cmd = 'ALTER TABLE [Table] DROP CONSTRAINT ' + @Val
Exec (@Cmd)
GO

ALTER TABLE [Table] ADD CONSTRAINT PK_Table
    PRIMARY KEY NONCLUSTERED (TableId)
GO

CREATE UNIQUE CLUSTERED INDEX IX_Table_Column
    ON Table (Column)
GO

推薦答案

你可以查一下約束的名字,寫一點動態(tài) SQL 來處理 drop.

You can look up the name of the constraint and write a bit of dynamic SQL to handle the drop.

SELECT name 
    FROM sys.key_constraints 
    WHERE parent_object_id = object_id('YourSchemaName.YourTableName')
        AND type = 'PK';

這篇關(guān)于用于刪除具有系統(tǒng)生成名稱的 PK 約束的 SQL Server 2008 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 成人免费视频国产免费 | 欧洲精品一区二区 | 国产香蕉av| 国产在线中文字幕 | 在线观看日韩欧美 | 就爱啪啪网| 国产精品网站在线观看 | 成人a视频 | av手机天堂 | 国产又粗又猛又黄又爽的视频 | 免费看黄色大片 | 黄色一级免费看 | 国产小视频在线播放 | 亚洲高清在线视频 | 欧美黑人一区二区三区 | 国产又黄又猛 | 国产精品一区在线播放 | 中文字幕在线免费观看视频 | 天天干夜夜拍 | 十八岁毛片 | 国产精品久久久久久久久久久久午夜片 | 成人毛片在线播放 | 黄色伊人 | 国产精品日韩欧美 | 日韩视频网 | 毛片在线免费 | 国产免费一区二区 | 91福利网站 | 国产香蕉视频 | 亚洲一级二级 | 午夜精品久久久久久久 | 懂色av一区二区夜夜嗨 | 茄子视频色 | 日韩免费精品视频 | 国产成人精| 国产乱码精品一品二品 | 五月婷婷综合激情 | 欧美一级黄色大片 | aa一级片 | 日韩精品在线观看视频 | 国产伦理一区二区 |