在一个操作中运行多个SQL语句 [英] Running multiple SQL statements in the one operation

查看:97
本文介绍了在一个操作中运行多个SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ADO一次在MS Access中创建多个表.是否可以在一个操作中执行多个语句?例如:

I'm trying to use ADO to create several tables at once, into MS Access. Is it possible to do multiple statements in the one operation? For instance:

...
// I have omitted the field details 
CString sQuery = "CREATE TABLE [Table1] (..., PRIMARY KEY ([ID])); \nCREATE TABLE [Table2] (..., PRIMARY KEY ([ID]));";
oRecordset.Open(oDatabase.m_pConnection, sQuery)

这是由于"Syntax Error in CREATE TABLE statement"而失败的,尽管每个create语句都可以完美地自己工作.有没有办法做这种事情?还有一些语句可以添加约束,添加索引等,我真的很希望能够做到这一点,这样就不必将字符串拆分成单独的部分.

This fails due to a "Syntax Error in CREATE TABLE statement", although each of the create statements work on their own perfectly. Is there a way of doing this sort of thing? There will also be statements to add constraints, add indexing, etc., and I'd really like to be able to do it so that I don't have to split up the string into separate parts.

推荐答案

ADO到MS Access不支持批处理SQL语句.您需要将每个语句作为单独的执行来运行.

ADO to MS Access does not support batch SQL statements. You need to run each statement as a separate execution.

这篇关于在一个操作中运行多个SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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