“如果不存在"SQL CE 失败 [英] "If not exists" fails on SQL CE

查看:21
本文介绍了“如果不存在"SQL CE 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个意想不到的问题.我正在制作一个脚本来更新 SQL CE 数据库上的架构.这不会运行:

I've got an unexpected problem. I'm making a script to update the schema on a SQL CE database. This won't run:

if not exists
(
    Select column_name from information_schema.columns
    where column_name = 'TempTestField' 
        and table_name = 'Inventory_Master_File' 
)
    Alter table Inventory_Master_File
      add TempTestField nvarchar(10) null   

我认为这是因为我使用了 SQL CE 不支持的东西.有人知道怎么做吗?我试过重新排列脚本,但无法正常工作.我试过改变表......不存在的地方......".

I think this is because I'm using stuff that isn't supported in SQL CE. Anyone know how to do this? I've tried rearranging the script and can't get anything to work. I tried "alter table ... where not exists ...".

请注意,select"部分和alter"部分运行良好.问题是如果不存在".我知道还有一些其他关于使用 SQL CE 的问题的帖子,但我找不到这个特定问题的答案.

Note that the "select" part runs fine and also the "alter" part. The problem is "if not exists". I know there are some other postings regarding problems like this using SQL CE but I couldn't find an answer to this particular problem.

干杯
标记

我花了一个多小时寻找解决方案.我发现很多帖子都在寻求类似问题的帮助,但我仍然不知道如何解决它.我真的不想在 C# 代码中这样做.我需要在 SQL 脚本中执行此操作.我不敢相信这种基本的东西会造成如此大的困难:(

I've spent over an hour looking for a solution. I've found many postings asking for help with similar problems but I've still got no idea how to fix it. I really don't want to do this in C# code. I need to do this in a SQL script. I can't believe something this basic is causing so much difficulty :(

推荐答案

SQL CE 似乎根本不支持任何过程扩展;只有 1970 年代的 DDL 和 DML.

It appears that SQL CE does not support any procedural extensions at all; only DDL and DML like from the 1970s.

您要么必须将过程逻辑放入您的应用程序(C# 或其他)中,要么转到具有过程扩展的可嵌入数据库,例如 SQLite.

You will either have to put procedural logic in your application (C# or whatever) or go to an embeddable database with procedural extensions, like SQLite.

这篇关于“如果不存在"SQL CE 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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