新聞中心
如果sql server刪除數(shù)據(jù)庫,要?jiǎng)h除的列有默認(rèn)值,實(shí)現(xiàn)的方法和普通sql server刪除方法有所不同,下面就讓我們來一起了解一下sql server刪除有默認(rèn)值的列的方法。

專注于為中小企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)兗州免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了超過千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
alter table article drop [列名]
來刪隊(duì)列
但在Sql server數(shù)據(jù)庫,如果這個(gè)列有默認(rèn)值,這樣刪除列會(huì)報(bào)錯(cuò),這時(shí)要?jiǎng)h除列的默認(rèn)值
declare @name varchar(20)
select @name=b.name from syscolumns a,sysobjects b where a.id=object_id('[表名]') and b.id=a.cdefault and a.name='[列名]' and b.name like 'DF%'
exec('alter table article drop constraint '+@name)
alter table [表名] drop column [列名]
其它:
刪除索引時(shí)Access為:
drop index indexName on tableName
sql 為:drop index tableName.indexName
mssql給表添加主索引:
alter table tablename add constraint [DF_tablename] default (1) for column
建帶主索引表:
create table tablename (id int identity(1,1) not null constraint PK_tablename primary key, column1 nvarchar(250) null)
【編輯推薦】
SQL Server創(chuàng)建表語句介紹
SQL server服務(wù)器版的安裝方法
帶您了解SQL Server游標(biāo)
SQL Server的優(yōu)點(diǎn)和缺點(diǎn)
SQL Server驗(yàn)證方法選擇
網(wǎng)頁標(biāo)題:sqlserver刪除有默認(rèn)值的列的方法
文章地址:http://fisionsoft.com.cn/article/dpdhcch.html


咨詢
建站咨詢
