The main problem is this line
SET TEMPORARY OPTION QUERY_PLAN_AS_HTML_DIRECTORY = ‘#WHAT SHOULD I TYPE HERE?, THERE ARE ONLY DATABASES ON MY LEFT HAND SIDE’;
I don't understand the concept of directories in database.
I've read what the option QUERY_PLAN_AS_HTML_DIRECTORY does
which explains the option. And I came to know about query plan from this pdf while looking for sources to optimize query.
Pages 13 & 14 in the document you linked explain that this should be a directory on the system that Sybase IQ is installed on, and it should probably be in the path of the Sybase IQ installation to ensure that the database can write to it.
From the PDF:
Note: Set the Query_Plan_As_HTML_Directory variable to an existing directory, or the HTML file will
show up in the closest existing directory.
In the example, they used '/opt/sybase/TPCHDB/QueryPlans' likely because IQ is installed in /opt/sybase
So the command for setting it permanently is:
set option public.Query_Plan_As_HTML_Directory = '/opt/sybase/TPCHDB/QueryPlans';
I assume set temporary is a per session setting, so the syntax would be:
set temporary option public.Query_Plan_As_HTML_Directory = '/opt/sybase/TPCHDB/QueryPlans';
Related
I'm looking for a way to automatize a copy of a database each day on the same SQL Server.
For example, I have a database MyDB. I would like, each day, do a copy of MyDB in a MyDB_TEST on the same server.
Is there any simple script to do this "simple" task ?
I found this script:
backup database OriginalDB
to disk = 'D:\backup\OriginalDB_full.bak'
with init, stats =10;
restore database new_db_name
from disk = 'D:\backup\OriginalDB_full.bak'
with stats =10, recovery,
move 'logical_Data_file' to 'D:\data\new_db_name.mdf',
move 'logical_log_file' to 'L:\log\new_db_name_log.ldf'
But I don't understand for what to replace in 'logical_Data_file' and 'logical_log_file'.
It's a move and I want a copy of my database...Why these two latest lines are "move" ?
I think I misunderstand this script...anyone could help me please?
EDIT :
I just edited my code like this :
backup database MY_DB
to disk = 'D:\BACKUP\MY_DB.bak'
with init, stats =10;
restore database MY_DB_NEW
from disk = 'D:\BACKUP\MY_DB.bak'
with stats =10, recovery,
move 'D:\Microsoft SQL Server\MSSQL12.SQLDIVALTO\MSSQL\DATA\MY_DB.mdf' to 'D:\Microsoft SQL Server\MSSQL12.SQLDIVALTO\MSSQL\DATA\MY_DB_new.mdf',
move 'D:\Microsoft SQL Server\MSSQL12.SQLDIVALTO\MSSQL\DATA\MY_DB_log.mdf' to 'D:\Microsoft SQL Server\MSSQL12.SQLDIVALTO\MSSQL\DATA\MY_DB_new_log.ldf'
And I sadly get an error telling the logical file "MY_DB.mdf" is not a part of the My_DB_New database...use RESTORE FILELISTONLY to get logicals file name.
I don't understand where is my mistake in this script, any inputs?
When you RESTORE a database, unless you specify otherwise it would create the same files that it had in the previously; same name, same path. As you want a copy, that would be overwriting the existing ones. That would, obviously fail, as those files are in use by your original database.
Therefore you need tell the instance to put the database files ("move" them) to a different path, hence the MOVE clause. This means that you then don't have the 2 databases conflicting over trying to use or write other each others files.
Side note, this type of thing does normally, however, tend to suggest an xy problem, though that is a different question.
CORRECTION:
I wasn't putting the logical file name but the file name instead.
Just put the logical file name without the path!
Is it possible to run a SQL script without qualifying the database name?
Currently, we are using the program like below,
SELECT I.XXXX_LOC_SKEY,
C.COUNTRY_SKEY
FROM
DEV_XXXX_DB.STAGING.XX_TABLE_LOCATION_SALES F,
DEV_XXXX_PRESENTATION_DB.DIMS.XXXX_LOCATIONS_D I,
DEV_XXXX_PRESENTATION_DB.DIMS.COUNTRY_D C,
DEV_XXXX_PRESENTATION_DB.DIMS.XXXX_DAILY_CALENDAR_D H
WHERE
F.STORE_CODE = I.DOOR
AND I.CHANNEL = 'XXXX'
AND F.COUNTRY = C.COUNTRY_CODE
AND I.COUNTRY_SKEY = C.COUNTRY_SKEY
AND F.DATE = H.DATE;
We would like to run the same script, without mentioning the database names as below.
SELECT I.XXXX_LOC_SKEY,
C.COUNTRY_SKEY
FROM
STAGING.XX_TABLE_LOCATION_SALES F,
DIMS.XXXX_LOCATIONS_D I,
DIMS.COUNTRY_D C,
DIMS.XXXX_DAILY_CALENDAR_D H
WHERE
F.STORE_CODE = I.DOOR
AND I.CHANNEL = 'XXXX'
AND F.COUNTRY = C.COUNTRY_CODE
AND I.COUNTRY_SKEY = C.COUNTRY_SKEY
AND F.DATE = H.DATE;
This is how unqualified objects are resolved:
https://docs.snowflake.net/manuals/sql-reference/name-resolution.html.
Note you can customize the SEARCH_PATH to search multiple schemas.
Alternatively you can put the fully qualified names in variable:
set f = 'DEV_XXXX_DB.STAGING.XX_TABLE_LOCATION_SALES';
select f.* from table($f) f;
select f.* from identifier($f) f;
Although the snowflake Web GUI remembers your last database, and other eg. ETL tools may configure a default database for a connection, Snowflake has no concept of a default database. All tools including the Web GUI have to issue the following command to set the database according to tool configuration:
USE DATABASE db_name;
If you want to avoid referencing a database in a command, you have to use the USE DATABASE command beforehand in the session.
Inferring a bit based on the SQL provided, you have embedded the environment into your database name (DEV_XXXX_DB). Since you have multiple databases per environment, this forces you to explicitly add the database name to every sql which crosses DB as SimonD has pointed out.
If you haven't discovered this yet, you're going to have a really hard time promoting code between environments b/c everywhere you're going to have to replace DEV_XXXX_DB with PRD_XXXX_DB.
If you're not that far down the journey of Snowflake implementation, I would suggest that you rethink your DB.SCHEMA strategy and create just 1 DB per environment (env_XXXX_DB) and put all the schemas w/in that DB (env_XXXX_DB.STAGING, env_XXXX_DB.DIMS).
If you have many databases but most of the data comes from one of them, you can create views in the one database pointing across to the other one. That way all of your objects can be queried without needing the database.
i.e. CREATE VIEW MY_VIEW as SELECT * FROM DATABASE.SCHEMA.TABLE
I can see your SQL accessing the data from different database then you have run SQL with fully qualified name of the object.
If snowflake current session is pointing to the location of the object then you can run SQL without qualifying the database name.
I am Sybase BO Developer.
Looking for possible option top copy data from Sybase IQ production and load to QA/UAT.
Need only subset of data(based on dates), not full table.
What are the possible options.
Thank You
Binu Varghese
Check this
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc00170.1540/doc/html/san1288042643642.html and the examples at http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc00170.1540/doc/html/san1288042645377.html
The idea is that you set temp options for file name, directory etc, then run a query and the result set is sent to a file. Then you must write a load command in order to load this file. It seems a bit confusing at first but it is very fast
In Ms-SQL Server to restore database I have a script as below but would like to parameterize the database name, path and file name in an SSIS Package, how do I do that?
Details:
The script, which works, I got this by right click at Restore in Ms SQL server:
USE [master]
RESTORE DATABASE [DataSystem2014] FROM DISK = N'F:\Folders\99_Temp\12_DataSystem\DataSystem_20140915_181216.BAK' WITH FILE = 1, MOVE N'DataSystem2014' TO N'F:\DatabaseFiles\DataSystem2014_Primary.mdf', MOVE N'DataSystem2014_log' TO N'F:\DatabaseLogFiles\DataSystem2014_Primary.ldf', NOUNLOAD, STATS = 5
GO
but I'd like to use above as an SQL task in an SSIS package, and I couldn't properly parameterize the database name ( [DataSystem2014] ) or the path ( F:\Folders\99_Temp\12_DataSystem\ ) or the file name ( DataSystem_20140915_181216.BAK ).
The database name will be fairly stable, but would like to bring it in to the SQL statement as a parameter, path might change but also stable enough, the file name always changes. I tried a few versions, used ? and parameter mapping, used #[User::Variable] in SQL statement, but couldn't get them working, always error messages.
Is this something I could get some help with, how to do this, please?
The Task for issuing SQL Statements is called the Execute SQL Task. Depending on your Connection Manager type, you will use different characters for placeholders. Map Query Parameters
Generally speaking, people use an OLE DB connection manager when working with SQL Server so the replacement character is a ?. That is going to be an ordinal based replacement token so even if you have the same string in there N times, you would be having to add N ? and make N variable mappings.
Looking at your query,
RESTORE DATABASE
[DataSystem2014]
FROM DISK = N'F:\Folders\99_Temp\12_DataSystem\DataSystem_20140915_181216.BAK' WITH FILE = 1
, MOVE N'DataSystem2014' TO N'F:\DatabaseFiles\DataSystem2014_Primary.mdf'
, MOVE N'DataSystem2014_log' TO N'F:\DatabaseLogFiles\DataSystem2014_Primary.ldf'
, NOUNLOAD
, STATS = 5;
it could be as heavily parameterized as this
RESTORE DATABASE
?
FROM
DISK = ? WITH FILE = 1
, MOVE ? TO ?
, MOVE ? TO ?
, NOUNLOAD
, STATS = 5;
Since those are all unique-ish values, I'd create a number of Variables within SSIS to hold their values. Actually, I'd create more Variables than I directly map.
For example, my restored database, DataSystem2014, name might always match the virtual name of the data and log so knowing one, I could derive the other values. The mechanism for deriving values is an Expression. Thus if create a Variable called #[User::BaseDBName], I could then create #[User::DBLogName] by setting EvaluateAsExpression = true and then using a formula like
#[User::BaseDBName] + "_log"
You can see in the linked MSDN article how actually map these Variables to their placeholders in the query.
Where this all falls apart though, at least in my mind, is when you have multiple data files. You're now looking at building your restore command dynamically.
I'm assuming you know what you are doing with parameterized execute sql tasks and skip right to the solution I had when doing this.
declare variables in the sql with quotename('?') and then build dynamic sql to execute the restore statement.
hope it helps.
Trying to detective out what is in a certain file ("HHS_WCE4.ARMV4.CAB"), I searched my hard drive for any references to that. One of the results Fileseek* was in C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Template Data\tempdb.mdf
[consider this an asterisk] Why, oh why, doesn't Windows 7 come with a file search utility? their previous one, although kind of lame in some ways, was still one of the most useful applets/utilities for daily usage.
I tried to open that database to see what reference it could have to "HHS_WCE4.ARMV4.CAB" but it says it can't see itself in one pane after exposing the same thing on another pane:
Am I doing something wrong? Is there another way to examine the contents of tempdb?
Note: I tried to connect to this first via Add Connection > Build data context automatically > Default (LINQ to SQL) > Next > (localdb)\v11.0 > Attach Database File > Test, but get:
tempdb is not a table, it is a database.
however, you are trying to select from it - you can't treat a database as an object in this case. you have to select from a table.