设置现有字段为not null

wojiaocaipeng 2012-01-12 08:04:30
我现在有一个表 building
其中有个列是buildingID
现在这个列是可以为空的
怎么样用SQL语句让他not null?
在线等。。求速度。。。
谢谢了
...全文
304 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yslwl 2012-01-14
  • 打赏
  • 举报
回复
update building set buildingID=[非null的值] where buildingID is null

alter table building alter column buildingID [数据类型] not null
还有设定该字段的默认值,否则后面的数会出错的
txws1119 2012-01-13
  • 打赏
  • 举报
回复
直接在sql企业管理器里设置好了
q806294478 2012-01-13
  • 打赏
  • 举报
回复
只有列中不包含空值时,才可以在 ALTER COLUMN 中指定 NOT NULL。必须将空值更新为某个值后,才允许执行 ALTER COLUMN NOT NULL 语句
UPDATE building SET buildingid = '' WHERE buildingid IS NULL
ALTER TABLE building ALTER column buildingid 数据类型 NOT NULL
唐诗三百首 2012-01-13
  • 打赏
  • 举报
回复
要先把null的数据修改为非null值,否则会出错喔.

update building set buildingID=[非null的值] where buildingID is null

alter table building alter column buildingID [数据类型] not null
小和桑 2012-01-13
  • 打赏
  • 举报
回复
alter table building alter column buildingID 数据类型 not null;
碧雨溪风 2012-01-12
  • 打赏
  • 举报
回复
标准格式:

alter table 表名称
alter column 要修改的列名 此列的数据类型 not null

注释:这条语句两个作用,其中之一就是提示你说的 修改列为非空;第二个作用就是 修改列的数据类型或者长度


希望对你有用。

叶子 2012-01-12
  • 打赏
  • 举报
回复
先把该列的数据都补充上,然后按上面大家给出的语句执行即可。
勿勿 2012-01-12
  • 打赏
  • 举报
回复
alter table building alter column buildingID 数据类型 not null;

Spade_J 2012-01-12
  • 打赏
  • 举报
回复
alter table building alter column buildingID int not null
百年树人 2012-01-12
  • 打赏
  • 举报
回复
alter table building alter column buildingID 类型 not null;

也可以通过界面上操作,更简便。

不过改之前你要把原来的为空的内容改为不为空

34,575

社区成员

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

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