sql查询alter列 [英] sql query for alter column

查看:99
本文介绍了sql查询alter列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在表中添加了一个列.但我将其添加为空.我想将其更改为非null.当我使用此查询进行更改时

alter table tbl_user_login alter column created_date datetime not null



它显示了一个错误
无法将值NULL插入表"customer_habitat_afsal.dbo.tbl_user_login"的"created_date"列中;列不允许为空. UPDATE失败.



我该怎么办?
帮帮我..
在此先感谢

解决方案

首先用任意数据(例如当前日期时间)填充空值,然后更改该列:

 更新 tbl_user_login  set  created_date = getdate()更改  tbl_user_login 更改  created_date 日期时间 不是  更新 tbl_user_login  set  created_date = @ Date  更改 表格 tbl_user_login 更改  created_date 日期时间 不是 

Firstly fill the null values with an arbitrary data for example current date time then alter that column :

update tbl_user_login set created_date= getdate() where created_dateis null ;


alter table tbl_user_login alter column created_date datetime not null



Hope it helps.


SQL Server is checking the values in the table so they do not violate the not null and they do hence the error.

You can insert values into the null columns and rerun the query.


first enter current date or anyother date in this field as you want than alter the column. then it will work. because in your field there is null value stored so it is giving error.

update tbl_user_login set created_date=@Date where created_date is null
alter table tbl_user_login alter column created_date datetime not null


这篇关于sql查询alter列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆