sql-scripts

script to restore database sql server from bak file, doesn't work

老子叫甜甜 提交于 2019-12-03 10:14:38
I have an empty database: DB_Clients And I want to restore the database from a .bak file: OldDBClients.bak This is the path: C:\OldDBClients.bak And this is my script: USE [master] GO RESTORE DATABASE DB_Clients FROM DISK = 'C:\OldDBClients.bak' When I execute it, I get this error message: Msg 3154, Level 16, State 4, Line 15 The backup set holds a backup of a database other than the existing 'DB_Clients' database. Msg 3013, Level 16, State 1, Line 15 RESTORE DATABASE is terminating abnormally. Can someone tell me why this happen? I have to point that the file has the permissions to read and

Spring boot. Run SQL scripts and get data on application startup

谁说我不能喝 提交于 2019-12-03 08:52:21
问题 I am developing a spring boot application. At the moment some of my configs are hard coded (e.g. Hystrix properties). So I would like to get these configs on my application start up time or just after that. Is it possible to do that using spring boot? I mean to run SQL script on start up and get data. How should properties/configs be retrieved and stored in my application? I am using MyBatis and Oracle DB. 回答1: By default, Spring-Boot loads data.sql and/or data-${platform}.sql . However, keep

Mysql: How to call sql script file from other sql script file?

六眼飞鱼酱① 提交于 2019-12-03 01:35:53
Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many such scripts for each of required tables. Now i want to write a script that call all of these script files in a sequence so basically I want another script file createTables.sql. Mysql provides option to execute a script file from "mysql" shell application but could find some command like exec c:/myscripts/mytable.sql . Please tell me if there is any command that can be written in sql script itself to call other one in latest mysql versions or alternative for same. Thanks You can use source command. So your

executing a .sql file in sql plus terminal

送分小仙女□ 提交于 2019-12-03 01:17:40
I have written couple of sql scripts in a text file and saved them with a .sql extension. I want to execute these scripts in the sql plus terminal without having to manually type the standalone sql scripts, but i'm struggling with it. If someone could list out the steps involved I would be very grateful. I could copy and paste those scripts in the terminal but that is not what I am looking at, I want to see if there is a way to provide the path to the scripts in the sql plus editor. If your filename is myQueries.sql, just type SQL>@/path/to/my/query/myQueries.sql SQL>/ 来源: https:/

Why can't I write DDL directly after a PLSQL anonymous block?

社会主义新天地 提交于 2019-12-02 16:51:37
问题 I have the following simple script. declare begin null; end; create table &&DB_SCHEMA..test_table ( test_column varchar(20) ); Executing it ends with the following error ORA-06550: line 6, column 1: PLS-00103: Encountered the symbol "CREATE" 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: Can't I use the DDL directly after an anonymous block? Am I forced to do it with EXECUTE IMMEDIATE inside the anonymous block? 回答1: You are simply missing a '/': SQL>

Execute scripts by relative path in Oracle SQL Developer

混江龙づ霸主 提交于 2019-12-01 05:19:46
First, this question relates to Oracle SQL Developer 3.2 , not SQL*Plus or iSQL, etc. I've done a bunch of searching but haven't found a straight answer. I have several collections of scripts that I'm trying to automate (and btw, my SQL experience is pretty basic and mostly MS-based). The trouble I'm having is executing them by a relative path. for example, assume this setup: scripts/A/runAll.sql | /A1.sql | /A2.sql | /B/runAll.sql /B1.sql /B2.sql I would like to have a file scripts/runEverything.sql something like this: @@/A/runAll.sql @@/B/runAll.sql scripts/A/runAll.sql: @@/A1.sql @@/A2.sql

Execute scripts by relative path in Oracle SQL Developer

ⅰ亾dé卋堺 提交于 2019-12-01 02:16:40
问题 First, this question relates to Oracle SQL Developer 3.2 , not SQL*Plus or iSQL, etc. I've done a bunch of searching but haven't found a straight answer. I have several collections of scripts that I'm trying to automate (and btw, my SQL experience is pretty basic and mostly MS-based). The trouble I'm having is executing them by a relative path. for example, assume this setup: scripts/A/runAll.sql | /A1.sql | /A2.sql | /B/runAll.sql /B1.sql /B2.sql I would like to have a file scripts

T-SQL STOP or ABORT command in SQL Server

偶尔善良 提交于 2019-11-30 14:36:10
问题 Is there a command in Microsoft SQL Server T-SQL to tell the script to stop processing? I have a script that I want to keep for archival purposes, but I don't want anyone to run it. 回答1: An alternate solution could be to alter the flow of execution of your script by using the GOTO statement... DECLARE @RunScript bit; SET @RunScript = 0; IF @RunScript != 1 BEGIN RAISERROR ('Raise Error does not stop processing, so we will call GOTO to skip over the script', 1, 1); GOTO Skipper -- This will

T-SQL STOP or ABORT command in SQL Server

陌路散爱 提交于 2019-11-30 10:41:40
Is there a command in Microsoft SQL Server T-SQL to tell the script to stop processing? I have a script that I want to keep for archival purposes, but I don't want anyone to run it. An alternate solution could be to alter the flow of execution of your script by using the GOTO statement... DECLARE @RunScript bit; SET @RunScript = 0; IF @RunScript != 1 BEGIN RAISERROR ('Raise Error does not stop processing, so we will call GOTO to skip over the script', 1, 1); GOTO Skipper -- This will skip over the script and go to Skipper END PRINT 'This is where your working script can go'; PRINT 'This is

MySQL columns with DEFAULT NULL - stylistic choice, or is it?

℡╲_俬逩灬. 提交于 2019-11-29 09:09:05
In many flavors of SQL, there are three ways you can implicitly set a column to NULL on every row insertion. These are: columnname type NULL columnname type DEFAULT NULL columnname type NULL DEFAULT NULL I.e. the first one sets the NULL flag (as opposed to NOT NULL), second one leaves the NULL flag to the default value, and the third one sets the NULL flag and sets the implicit value as NULL. I've heard about how in Microsoft SQL, the second variation is not exactly the same since you can also customize the default value of the NULL flag for tables or schemas. But for MySQL, I don't believe