关键词和代码块的TSQL替换
我有 TSQL 块,我想为其创建宏,然后在我的 SQL 文件中重用。我希望这只是“编译”时的事情。
例如:
?set? COMMON = "Field1 int, Field2 char(1),";
?set? MAKEONE = "create table";
MAKEONE XXX (
COMMON
Field3 int
);
请不要问我为什么要...:)
...它是针对 SQL Server 的。
好的,那么 SQL 的条件执行呢:
?set? ISYES = true;
?if? ISYES
create table AAA (...)
?else?
create table BBB (...)
I have blocks of TSQL that I want to create a MACRO for and then reuse in my SQL file. I want this to be a 'compile' time thing only.
Eg:
?set? COMMON = "Field1 int, Field2 char(1),";
?set? MAKEONE = "create table";
MAKEONE XXX (
COMMON
Field3 int
);
Please dont ask why I would want to ... :)
... it is for SQL Server.
Ok, what about conditional execution of SQL:
?set? ISYES = true;
?if? ISYES
create table AAA (...)
?else?
create table BBB (...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所要求的内容在 SQL 术语中没有什么意义
根据您的示例:
A CREATE TABLE 正是:CREATE TABLE。为什么要宏呢?您不会替换“CREATE PROCEDURE”。
拥有“公共”字段将表明设计不佳
您还必须考虑:
操作 现在,您要解决的业务问题是什么?
而不是询问您选择的解决方案...
编辑:问题更新为我在上面输入的内容:
请注意,SQL 中的大部分 DDL 必须位于其自己的批处理中或批处理中的第一个语句中。因此再次使用动态SQL
What you are asking makes little sense in SQL terms
Based on your examples:
A CREATE TABLE is exactly that: a CREATE TABLE. Why Macro it? You aren't going to substitute "CREATE PROCEDURE".
Having "common" fields would indicate poor design
You also have to consider:
Now, what is the business problem you are trying to solve?
Instead of asking about your chosen solution...
Edit: question updated as I typed above:
Note that much of DDL in SQL must be in it's own batch or the first statement in a batch. Hence use of dynamic SQL again