Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running SQL Script (with GO commands) from VFP
Message
De
16/02/2018 14:04:03
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01658170
Message ID:
01658171
Vues:
555
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform