How to Encrypt SQL file - sql

sql) that contains all my stored procedures. Now I need the admin to run it in the database without him knowing the contents of the file.
How do I do this?
Ok I thought of running a .bat file that will run the script and deletes itself at the end. I already have the delete code as I have done it before. I only need to know now how to run sqlcmd in .bat file. Can you help me?

Related

How to protect or open protected excel file using SSIS

I have a simple SSIS package. Extract data from database, load into an .xls file and then email to users using sp_send_dbmail task. I have few different reports I do this task for. Now the issue is that I need to add password to those files before sending to users. I can do this in two ways: password protect the template manually and load the file in SSIS OR load and password protect the file (both) in SSIS. SSIS has limitations where it cannot open protected file neither has any way to protect the file as a task. Here are the few ways I have research I can do this:
Excel Interop via Script Task: Upon a lot of research, I found its not the best practice as it causes a lot of server issues and requires licensing so i dropped this idea.
OpenXML via Script Task: It only works with .xlsx but I have .xls file and I can only use .xls
Excel Macros: I have created a Macro which perfectly protects a file but the issue arises on how to execute this. Upon research found out it can be executed using Interop.
Write a batch file that will execute Excel Macros: I haven't really found a solution on how to run them using batch file (if it is even possible)
Use PowerShell to protect the file and then execute them through Execute Process task in SSIS. I am not familiar with PowerShell but I have researching and saw it is possible.
I have done A LOT of research on it and I am unable to find a right solution. My knowledge is very limited to SQL. Any suggestion would be greatly appreciated, thanks!
Load the file normally then lock it using a powershell script or a macro (not sure if this is possible). Locking and unlocking are external to SSIS, so its best handled by some sort of scripting language such as powershell. Read this
Lock Unlock excel files using PS script

How to run .sql file in Oracle SQL developer tool to import database?

I have exported database from Oracle SQL developer tool into .sql file. Now I want to run this file which is of size 500+ MB.
I read about running scripts here, but I didn't understand the way. Is there any command or query by which we can run this sql script by providing path?
You could execute the .sql file as a script in the SQL Developer worksheet. Either use the Run Script icon, or simply press F5.
For example,
#path\script.sql;
Remember, you need to put # as shown above.
But, if you have exported the database using database export utility of SQL Developer, then you should use the Import utility. Follow the steps mentioned here Importing and Exporting using the Oracle SQL Developer 3.0
You need to Open the SQL Developer first and then click on File option and browse to the location where your .sql is placed. Once you are at the location where file is placed double click on it, this will get the file open in SQL Developer. Now select all of the content of file (CTRL + A) and press F9 key. Just make sure there is a commit statement at the end of the .sql script so that the changes are persisted in the database
You can use Load function
Load TableName fullfilepath;

How to execute a 3 GB sql file

i have a 3GB sql file and i can't open directly on management studio,so,i have to split the file and execute the parts.but,how i'll split the file? or execute directly without outOfMemory exception?
i'm using SQL SERVER 2014 and i didn't have sucess restoring the .sql with cmd..
I have faced this before..Use sqlcmd utility.. very easy to use.. in this case you just have to give the path of one big script file with few other parameters. Refer to microsoft documentation.
Hope that helps
that sucks. you should be able to load the .sql file via command line. this is how most data warehousing companies load large db/sql files in order launch databases. this should NOT be opened with any IDEs and loading it via command line is the only way it's done.
if I were you I'd try to load the file via cmd again because that's the way to do it.

Running SQL script script/s on multiple databases at the same time (Parallel execution)

I currently use sqlcmd to execute scripts on a database within my deployment process. Now with multiple database one solution is to use this very script in a batch or foreach database. The problem with this, it applies the script to the database one at a time. I need something that can save time.
Can SQLCMD execute a script on multiple database in Parallel? If not, are there a script command I can leverage to accomplish this?
There are similar questions, but none with the right solution or the stress that it has to be a method to execute in Parallel which is the main goal.
The tool SQL Multi Script does exactly this, but its not open source plus I prefer scripting it out.
Any ideas?
Thanks in advance.
If you are using SSMS to run your SQLCMD script, you can use a group query to run again more than one server. I am not completely sure if it runs in parallel or not. Look here for more information
I was able to accomplish this using the following.
The user will set which databases to deploy to in a specific instance.
Foreach database it will generate a set of SQLCMD commands foreach script to deploy and place this in a batch file.
For Example: SQLCMD_Commands_DB1.bat and SQLCMD_Commands_DB2.bat
Foreach batch file created with will then generate a new master batch file with the START commands.
START "" "SQLCMD_Commands_DB1.bat"
START "" "SQLCMD_Commands_DB2.bat"
Execute the Master batch file which will deploy the database scripts in Parallel. I written this and it works as expected.

How to make my SQL Server Management Studio accept a .sql file

I have a .sql file I need to enter in to my database, but I can't find how to do it.
I'm using SQL Server Management Studio R2, but haven't found any options on how to add it.
When I try to attach it, I'm told that this file isn't a primary database file, so I can't do it...
EDIT: okay, I had the script execute. That worked.
A .SQL file is a script file that contain SQL commands. To run those commands you need to go to the menu: FILE, then OPEN and FILE..., browse and select the .SQL file and it will open it, you can then run it (F5). Make sure the current database is the one where you want those commands to occur within.
A .sql file is a script, not a database.
Will this work for you?
In Management Studio, click on menu File -> Open -> File -> navigate to the file.
After the file has opened, you can click F5 to run the SQL.
A .sql file is usually a script (DML, DDL, other commands) which can be run against a database. It may create objects, databases, add or remove data. You can open it (File...Open) in SSMS (or view it in any text editor) and then execute it (after carefully reviewing the script).
File->Open, browse to the file, load it. Make sure the right database is selected in the drop-down box above the editor. F5 to execute.