>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