从一个表到另一个表的插入数据的SQL子查询 [英] SQL SUB QUERY FOR INSERT DATA FROM ONE TABLE TO ANOTHER

查看:136
本文介绍了从一个表到另一个表的插入数据的SQL子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图将数据从一个表插入到onother.但是它给我你不能插入NULL值,因为它是一个NOT NULL字段.当我添加IS NOT NULL结时,但是仍然会出现相同的错误. />

查询:

HI i just tried to insert data from one table to onother.but it gives me you cannot insert NULL values since it is a NOT NULL feild.THEN i add IS NOT NULL junction.but still gives the same error.


QUERY :

INSERT INTO [AntronERP_DB].[dbo].[tblCountry](countryCode,countryName,secCode,stdCountryCode)
(SELECT [CountryCode],[CountryName],[Sector],[CountryCode]  FROM [ANTRONMASTERDB].[dbo].[CountryMaster]
WHERE  Sector  IS NOT NULL AND CountryCode <> 'UK' OR CountryCode <> 'LK' OR CountryCode <> 'US' )



错误代码:



ERROR CODE :

Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'secCode', table 'AntronERP_DB.dbo.tblCountry'; column does not allow nulls. INSERT fails.
The statement has been terminated.




谢谢!




ANybody help me on this issue.Thanks!

推荐答案

这意味着 secCode 列具有set属性allow null = false
修改表并勾选刻度线 允许Null 选项,然后尝试...

祝您编码愉快!
:)
this means secCode column has set property allow null = false
modify table and tick mark allow Null option then try...

Happy Coding!
:)


尝试以下操作(在countrycode子句周围添加括号):
Try the following (added parenthesis around the countrycode clause):
INSERT INTO [AntronERP_DB].[dbo].[tblCountry](countryCode,countryName,secCode,stdCountryCode)
(SELECT [CountryCode],[CountryName],[Sector],[CountryCode]  FROM [ANTRONMASTERDB].[dbo].[CountryMaster]
WHERE  Sector  IS NOT NULL AND (CountryCode <> 'UK' OR CountryCode <> 'LK' OR CountryCode <> 'US') )


这篇关于从一个表到另一个表的插入数据的SQL子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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