Open Sql Script with big size - sql-server

I have an SQL script file which it has big size " 1.4 GB "
when I try to open it in SQL SERVER Management Studio
it fails and give me message
The System can't find the file specified
when I try to open it with notepad++
file is too big to be opened by notepad++
so does it there anyway to open this script ?

Run this command in Command prompt by providing the required details. This command would execute the SQL file without opening the file.
sqlcmd -S <ServerName> -U <LoginUser> -P <Password> -d <DatabaseName> -i <Inputfilenamewithpath> -o <Outputfilenamewithpath>

Related

Why database creation command fails in SQLCMD in SQL Server docker for linux?

I use docker-compose.yml to load my SQL Server image inside a container.
After it's up and running, I create a command.sh shell and try to run it to create a database.
# command.sh
echo 'creating database from ->' $ModuleName
export query="'create database $ModuleName'"
echo $query
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P my_strong_password -Q $query
And it gives me this error:
Sqlcmd: 'database': Unknown Option. Enter '-?' for help.
Please note that I can't use -i switch to use an input .sql file, because I'm creating my queries programmatically in shell based on environment variables.
The output of sqlcmd -? shows how to use then -Q option. On windows this says [-Q "cmdline query" and exit].
But Windows and Linux differ (or are not consistent) in the use of single- or double quotes.
First option is to try: sqlcmd -Q "\"create database $ModuleName\""
Second option is:
Create a temporary file (i.e. /tmp/tmp.sql), and put the SQL statement in that script.
Use -i /tmp/tmp.sql to execute that script.

SQL Server Express backup script

I was able to perform backup for my SQL Server Express using this command at the command prompt:
SQLCMD -E -S testing\SQLEXPRESS –Q "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak'"
When I want to create a batch script using the command above in order to create a task scheduler to perform auto backup, it shows error as below:
Here is the batch code:
echo off
c: \
CD "C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn"
SQLCMD -E -S testing\SQLEXPRESS –Q "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak';"
I didn't put exit at bottom of it because I want to verify whether the command successfully run or not.
ERROR:
Sqlcmd: 'ûQ "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak' ': Unexpected argument. Enter '-?' for help.
Does anyone know how to fix this?
EDIT : I solve it by giving a semi column at the end and type it one by one instead of copy paste it

Linux cli tool to dump SQL Server schema to a text file

Do you know a reliable command line tool able to export SQL Server schema to a text file?
You can do this with mssql-scripter. Download through - pip install mssql-scripter.
The command you'll want to use is along the lines of:
$ mssql-scripter -S serverName -d databaseName -U user > ./my-schema.sql
The default is schema only (you can also specify --schema-and-data and --data-only). The command line will prompt for your password.
And you can pipe to stdout, sed, or a .sql file currently. Here's the GitHub page as this is an OSS repo - https://github.com/Microsoft/mssql-scripter. Please do file issues on the repo if you run into any.

How to use SSMS in command prompt

I want to make a link that would run ssms.exe , login and open a .sql file.
However this: SSMS.exe -E -d AB2014 work fine
when this SSMS.exe -E -d AB2014 "C:\Users\Kazz\Desktop\AB2014\SQLQuery.sql" opens the .sql 'file' but fails to login...
For my money, the tool to use when I just want to run a file (instead of have an interactive session with the server) is sqlcmd.exe. In your situation, it'd go something like:
sqlcmd -E -d AB2014 -i "C:\Users\Kazz\Desktop\AB2014\SQLQuery.sql" -S someServer

export MySql database with cmd

I'm using MySql 5.1 version and I'm trying to export mydatabase by cmd ,when I wrote this command :
C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqdump -uroot -ppassword mydatabase >mydatabase.sql
I get an Error
Access is denied
I don't Know what the problem
Help Pleas.....
What's your permissions on the directory you're running this command from? It may be trying to write the mydatabase.sql file to a directory you don't have permissions to.
First check if your command line recognizes mysql command. If not go to command and type in
set path=c:\wamp\bin\mysql\mysql5.1.36\bin
Then use this command to export your database
Go to directory where you have mysql. -u - for username -p - to prompt the password
C:\xampp\mysql\bin>mysqldump -u Username -pPassword DatabaseName > DatabaseName.sql
Note:It is better to use full path of the the sql file file.sql
To export database from dump file (in this case called filename.sql) use: mysql -u username -p password database_name > filename.sql
If you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. If you are using WAMP server then this is usually located in: C:\wamp\bin\mysql\mysql5.1.36\bin (*note the version of mysql might be different)
So you will: cd C:\wamp\bin\mysql\mysql5.1.36\bin
and then execute one of the above commands.

Resources