Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running SQL Script (with GO commands) from VFP
Message
From
16/02/2018 14:04:03
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01658170
Message ID:
01658171
Views:
563
>Hi everybody,
>
>I am wondering if there is a simple way to run SQL Script (.sql) file from VFP? I want to run create table + create triggers command as one sql script.
>
>I can, of course, use dynamic SQL to create the trigger or do it in two steps, but wondering if there is a way to just run the script?
>
>Thanks in advance.

Yes, there is. SQLEXEC() normally runs multiple statements, that is, a script.
LOCAL ODBC AS Integer
LOCAL Script AS String

m.ODBC = SQLCONNECT("YourDSN", "YourUID", "YourPWD")

TEXT TO m.Script NOSHOW
SET ANSI_NULLS ON;

SET QUOTED_IDENTIFIER ON;

CREATE TABLE [YourUID].[CreateTest](
	[SomeCol1] [int] NOT NULL,
	[Somecol2] [int] NOT NULL
) ON [PRIMARY];
ENDTEXT

? SQLEXEC(m.ODBC, m.Script)

SQLDISCONNECT(m.ODBC)
Update: full marks to Walter, for pointing out the necessity to separate table and triggers creation statements.
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform