gpt4 book ai didi

sql - 当 SQL 中的值为空时,如何在 INSERT 上跳过列条目?

转载 作者:行者123 更新时间:2023-12-03 01:03:44 25 4
gpt4 key购买 nike

我正在向数据库中插入大量行,但某些行的某些列为空白

如何插入而不为这些空白字段分配虚拟值?

       1 INSERT Leads VALUES('name', 'cityName', 5, 'anotherValue')
2 INSERT Leads VALUES('name', 'cityName', , 'anotherValue')
3 INSERT Leads VALUES('name', 'cityName', 2, 'anotherValue')
4 INSERT Leads VALUES('name', 'cityName', 9, 'anotherValue')

我的问题出在第 2 行,其中城市名称和另一个值之间有一个空白值。理想情况下,我希望该值保持为空。

感谢任何帮助。

谢谢!

最佳答案

您应该始终明确指定要插入的列 - 然后您可以省略那些您不想要的列:

INSERT INTO dbo.Leads(Col1, Col2, Col4) VALUES('name', 'cityName', 'anotherValue')

(在此示例中省略 Col3)

关于sql - 当 SQL 中的值为空时,如何在 INSERT 上跳过列条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7691184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com