2008-10-15 158 views

回答

3

當然。只需創建一個小應用程序,它可以獲取所需的所有.sql文件並執行它們。做到這一點在VB.NET如下:

Sub ExecuteSqlScript(FilePath As String) 

    Dim Script As String 
    Dim FileNumber As Integer 
    Dim Delimiter As String 
    Dim aSubscript() As String 
    Dim Subscript As String 
    Dim i As Long 

    Delimiter = ";" 
    FileNumber = FreeFile 
    Script = String(FileLen(FilePath), vbNullChar) 

    ' Grab the scripts inside the file 
    Open FilePath For Binary As #FileNumber 
    Get #FileNumber, , Script 
    Close #FileNumber 

    ' Put the scripts into an array 
    aSubscript = Split(Script, Delimiter) 

    ' Run each script in the array 
    For i = 0 To UBound(aSubscript) - 1 
     aSubscript(i) = Trim(aSubscript(i)) 
     Subscript = aSubscript(i) 
     CurrentProject.Connection.Execute Subscript 

    Next i 

End Sub 

來自實例:http://snipplr.com/view/3879/run-sql-script-from-external-file/

11

你可以試試這個:

exec master..xp_cmdshell 'osql -E -ix:\path\filename.sql' 

OSQL必須在路徑的完整文件名必須是已知的,登錄必須正確設置(選項-E或-U)

0

沒有理由排除存儲過程。你並不需要包括「任何其他形式的代碼,是不是SQL」,再加上任何其他解決方案

EXEC someothersp

這將需要(或同等學歷)。

你排除他們的原因是什麼?我肯定會認爲它會以另一種語言編寫代碼。

+1

我想他意味着他想從另一個SQL腳本中調用一個SQL腳本。不像Chris Ballance所建議的那樣,從外部腳本和語言中調用SQL腳本。 devio的解決方案是可行的,如果它需要全路徑可能會很痛苦。 – tjmoore 2010-08-31 13:21:20

相關問題