The requirement today is to write the creation of all tables to the storage process.
After receiving the script for creating a table, it is silly. There are 60-70 tables, including stored procedures and views.
How can this problem be solved.
The idea is to use shell scripts to execute SQL script files in the stored procedure.
Get the shell execution function through msdn: xp_cmdshell.
The following is a complete script:
Create Procedure Creattable
(
@ Username Varchar ( 200 ),
@ Password Varchar ( 200 ),
@ Filepath Varchar ( 200 ),
@ Trusted Bit
)
As
Begin
Set Nocount On ;
Declare @ Shell Varchar ( Max );
Exec SYS. sp_configure ' Show advanced options ' , 1 ;
-- Open Shell
Exec SYS. sp_configure ' Xp_mongoshell ' , 1
If @ Trusted = 1
Set @ Shell = ' Osql-e northwind-I ' + @ Filepath ;
Else
-- Use user name connection
Set @ Shell = ' Osql-u ' + @ Username + ' -P ' + @ Password + ' -D northwind-I ' + @ Filepath ;
Exec Master .. xp_mongoshell @ Shell ;
-- Close Shell
Exec SYS. sp_configure ' Xp_mongoshell ' , 0
End
go