改变栏位为not null且设Default值 ~~~在线等

cynthiabx 2009-04-24 03:39:20
请问一下,
表结构如下
create table tb (nameid int)

我要把nameid栏位改为not null 且设default为-1,应该怎么写呢
谢谢
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
taoistong 2009-04-24
  • 打赏
  • 举报
回复


create table tb1 (nameid int)

alter table tb1
alter column nameid int not null
alter table tb1
add CONSTRAINT taoistong1 default(-1) for nameid


cynthiabx 2009-04-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sdhdy 的回复:]
里面有数据吗?
[/Quote]
表里是有数据
nj_1st_excellence 2009-04-24
  • 打赏
  • 举报
回复


create table tt
(
id int,
nn int
)
alter table tt alter column id int not null

ALTER TABLE tt
ADD CONSTRAINT tt_id_def
DEFAULT -1 FOR id


htl258_Tony 2009-04-24
  • 打赏
  • 举报
回复
if object_id('tb') is not null drop table tb 
go
create table tb (nameid int)

alter table tb alter column nameid int not null
alter table tb add constraint df_nameid default(-1) for nameid
sdhdy 2009-04-24
  • 打赏
  • 举报
回复
里面有数据吗?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧