久久久久久久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 腳本的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問題描述

我正在嘗試向 SQL Server 2008 中的現(xiàn)有表添加聚集索引,它需要是一個(gè)自動(dòng)化腳本,因?yàn)樵摫泶嬖谟诳缍鄠€(gè)服務(wù)器的多個(gè)數(shù)據(jù)庫(kù)中.

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.

為了添加聚集索引,我需要?jiǎng)h除表上的 PK 約束,然后將其重新添加為非聚集索引.問題是 PK 約束的名稱是自動(dòng)生成的,并且在末尾附加了一個(gè) 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ù)庫(kù)的名稱都不同,我不知道如何編寫一個(gè)自動(dòng)化腳本,在我不知道約束名稱的表上刪除 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

推薦答案

你可以查一下約束的名字,寫一點(diǎn)動(dòng)態(tài) SQL 來(lái)處理 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 腳本的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問題和答案的組合))
主站蜘蛛池模板: 亚洲欧美网站 | 国产探花在线精品一区二区 | 日本精品久久 | 亚洲欧洲成人av每日更新 | 国内av在线| 亚洲精品欧美 | 免费v片在线观看 | 日韩成人精品在线观看 | 少妇久久久久 | 欧美精品一区二区三区在线播放 | 黄色网页在线观看 | av一二三四 | h视频免费在线观看 | 国产精品国产亚洲精品看不卡15 | 欧美激情欧美激情在线五月 | 日韩欧美在 | 四虎成人在线播放 | 国产极品粉嫩美女呻吟在线看人 | 国产日韩精品视频 | 亚洲精品字幕 | 欧美日韩国产精品一区 | 欧美久久久网站 | 久久久99精品免费观看 | 色综合天天天天做夜夜夜夜做 | 韩日精品在线观看 | 午夜亚洲| 国产免费一区二区三区 | 午夜看片网站 | 欧美激情亚洲天堂 | 曰批视频在线观看 | 国产清纯白嫩初高生在线播放视频 | 午夜精品久久久久久久久久久久久 | 欧美黑人又粗大 | 亚洲网站在线播放 | 国产资源在线观看 | 欧美成年网站 | 欧美日韩精品一区 | 国产亚洲精品久久yy50 | 久久久久久中文字幕 | 福利片一区二区 | 综合久久综合久久 |