sql修改欄位為空
發布時間: 2025-07-22 03:45:57
A. sql語句怎麼把不允許為空的屬性修改為允許為空
altertable表名altercolumn列名類型長度null
中文處替換一下就行
比如原來類型是varchar(10)
altertable表名altercolumn列名varchar(10)null
B. sql如何把查詢到的NULL替換成空值
1、這要看你如何保存你查詢的結果。只能是你把你查詢的結果保存為0,查詢不會改變原本存在的值。表名test,欄位a=.null.(int型),欄位b=1,欄位c=2 :select * from test into tabel test1
update set a=0 where a=.null。
2、用 IsNull(欄位名, '') 可以將NULL的欄位轉換為空值,這在多個欄位連接時很有用,因為NULL值+任何欄位都是NULL。
3、將NULL替換為空create procere fill_null@tablename varchar(100) --表名asdeclare @colname varchar(100)declare col_cur cursor for select c.name from syscolumns c,sysobjects o where c.id=o.id and o.name=@tablename open col_curfetch next from col_cur into @colnamewhile @@fetch_status!=-1beginexec ('update '+@tablename+' set '+@colname+'='''' where '+@colname+' is null' )fetch next from col_cur into @colnam endclose col_curdeallocate col_cur
熱點內容