新聞中心
刪除列操作是在使用Sql server數(shù)據(jù)庫中比較常見的操作,但是如果刪除的列有默認(rèn)值,那應(yīng)該如何操作呢?下面就將為您介紹Sql server中刪除有默認(rèn)值的列的方法。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供隆回網(wǎng)站建設(shè)、隆回做網(wǎng)站、隆回網(wǎng)站設(shè)計、隆回網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、隆回企業(yè)網(wǎng)站模板建站服務(wù),10多年隆回做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
Access數(shù)據(jù)庫里可以直接用alter table article drop [列名]來刪隊列,但在Sql server數(shù)據(jù)庫,如果這個列有默認(rèn)值,這樣刪除列會報錯,這時要刪除列的默認(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 [列名]
其它:
刪除索引時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)
本文名稱:Sqlserver中如何刪除有默認(rèn)值的列
網(wǎng)站路徑:http://m.fisionsoft.com.cn/article/dhshjdg.html


咨詢
建站咨詢
