visual-studio 使用 Visual Studio 2008 编辑 SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/196909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Editing SQL query with Visual Studio 2008
提问by Alexander Prokofyev
Would you recommend me the best approach to edit SQL query with Visual Studio 2008 Professional, please?
请您向我推荐使用 Visual Studio 2008 Professional 编辑 SQL 查询的最佳方法吗?
I know I can open Query window from context menu in Server Explorer and edit text in SQL Pane. But unfortunately I am not allowed to save query to a file and Find and Replace commands are not working there.
我知道我可以从服务器资源管理器的上下文菜单中打开查询窗口并在 SQL 窗格中编辑文本。但不幸的是,我不允许将查询保存到文件中,并且查找和替换命令在那里不起作用。
Alternatively I can open text file with extension .SQL in Visual Studio editor obtaining syntax highlighting and full editing capabilities but losing possibility to execute the script.
或者,我可以在 Visual Studio 编辑器中打开扩展名为 .SQL 的文本文件,获得语法突出显示和完整的编辑功能,但无法执行脚本。
Now I copy query text from one window to another and back but I hope there is better solution.
现在我将查询文本从一个窗口复制到另一个窗口并返回,但我希望有更好的解决方案。
Many thanks for suggestions!
非常感谢您的建议!
采纳答案by Jeffrey L Whitledge
If you create a Database project within your solution in Visual Studio, then you can set up a default database connection for that project. Then any *.sql files that are included in the database project can be executed against that connection. What I usually do is select the text to be exectued and right-click it, then select "Run Selection".
如果在 Visual Studio 的解决方案中创建数据库项目,则可以为该项目设置默认数据库连接。然后可以针对该连接执行包含在数据库项目中的任何 *.sql 文件。我通常做的是选择要执行的文本并右键单击它,然后选择“运行选择”。
You can set up any number of database connections under the "Database References" node in the solution explorer, and choose the one you want to run your query against.
您可以在解决方案资源管理器中的“数据库引用”节点下设置任意数量的数据库连接,然后选择要对其运行查询的连接。
回答by Alexander Prokofyev
When I have to connect to Sql Server, I use NetBeans, as it has a number of features that make it much easier to use than Visual Studio. One of these is intellisense, which is very useful when you have an alias for a table name and lots of long field names. The general handling of connections and connection pools is also much cleaner in NetBeans. I could go on, but suggest trying it for yourself. You will almost certainly need the Sql Server jdbc driver, which can be downloaded from http://msdn.microsoft.com/en-us/data/aa937724.aspx
当我必须连接到 Sql Server 时,我使用 NetBeans,因为它具有许多比 Visual Studio 更易于使用的功能。其中之一是智能感知,当您有表名的别名和许多长字段名时,它非常有用。NetBeans 中连接和连接池的一般处理也更加清晰。我可以继续,但建议您自己尝试一下。您几乎肯定需要 Sql Server jdbc 驱动程序,可以从http://msdn.microsoft.com/en-us/data/aa937724.aspx下载
回答by smaclell
Wow you are right, this is a real pain. Would it be acceptable for you to use a local copy of the SQL Management Studio (the name might be wrong)? You would be outside of VS but you could still edit your query and run it at the same time. Definitely not optimal but better than nothing.
哇,你是对的,这真的很痛苦。您是否可以使用 SQL Management Studio 的本地副本(名称可能有误)?您将在 VS 之外,但您仍然可以编辑您的查询并同时运行它。绝对不是最佳的,但总比没有好。
Good luck.
祝你好运。

