What does "thema.."<view_name> mean in sql server 2008? - sql-server

I have got a query which is as below:
SELECT * FROM thema.."<view_name>".
When I check all the schema in the db, I am not able to see any schema name called thema. Is it something which is internal to sql server 2008?

SQL Server uses up to four parts in a name: server.database.schema.table. If you omit the schema name (f.e. dbname..tablename) SQL Server will use the default schema for your user.

Related

Message "cross-database references are not implemented" for a simple query from SQL Server to PostgreSQL

I need to query PostgreSQL from SQL Server. I created a linked server connection (ODBC for PostgreSQL, the newest). It works on some schemas and not on the others. They're all on the same server.
For example this works:
SELECT * FROM LinkedPS.MyDatabase.Schema1.Table1
and this doesn't:
SELECT * FROM LinkedPS.MyDatabase.Schema2.Table2
I wasn't able to find any property which would cause this.

Query from SQL Server tables in Oracle using ODI

I have a database in Oracle and a database in SQL Server.
I want to write a query in Oracle and I need to use one of SQL Serever table in it.
Before I used database link but now I must to do this with ODI (Oracle Data Integrator).
The way I used before:
CREATE PUBLIC DATABASE LINK "DBLINK"
CONNECT TO "MatrisApp" IDENTIFIED BY VALUES ':1'
USING 'dg4msql';
INSERT
INTO everyday_deposit_temp ***/*this is a table in oracle*/***
(
"DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
)
SELECT "DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
FROM dbo.vw_deposit_changed#dblink
Please help me with this
The most common way to get data from MS SQL Server to Oracle through ODI is to use LKM MSSQL to ORACLE (BCP SQLLDR).
Now if you really want to use a dblink, I would try this approach:
Duplicate a Oracle IKM you want to use
In the definition tab, check the Multi-Connections checkbox and set Microsoft SQL Server for the Source Technology.
In the Options tab, add a new option DBLINK_NAME with Value type.
In the Tasks tab, find the task responsible of the insert and edit the target command to add this after the table name : #<%=odiRef.getOption("DBLINK_NAME")%>
Create a mapping using the new IKM. In the Physical tab, click on the target table and add the dblink name in the Option.

Change chosen SQL Server database in distributed database with Invantive Data Hub

We run a daily job to load Exact Online into a SQL Server database for reporting purposes with Sumatra.
We now want to redirect the SQL insert statement to another database on the same SQL Server.
Connections are:
<connection name="EOLIN_MUT" ...>
<database order="20" alias="eol" provider="ExactOnlineAll" connectionString="apiUrl=https://start.exactonline.nl;api-client-id=SOMETHING;apiredirecturl=https://eolclientredirect.invantive.com" />
<database order="10" alias="sql" provider="SqlServer" connectionString="Data Source=something;UID=datahub;PWD=moresecrets" AllowConnectionStringRewrite="false" />
I've already change the name of the connection from EOLIN to EOLIN_MUT but without result.
How can I redirect to another database?
You have three alternatives that you can use:
Change default database of user
Change default database on connection
Switch database.
To change default database of the user, have you SQL Admin change it in SQL Server. There is no database listed yet in your connection string.
To change default database of connection, see connectionstrings.com on SQL Server. Add database=NAME; to your connection string in settings.xml.
To switch database, change the Invantive SQL script you use by adding:
use XYZ#sql
where XYZ is the intended default database on SQL Server and sql is the alias on the SQL Server data container.
With use, you can also select multiple data containers, such as:
use XYZ#sql, 123123#eol, 456456#eol
which select XYZ on SQL Server and companies/administrations/divisions 123123 and 456456 on Exact Online with alias eol. More documentation on use statements.
Please note that the default SQL Server provider of Invantive does NOT allow you to select multiple database to be used for a query. So when using Exact Globe or Navision, you will need to explicitly include all companies in your query.

Update SAS 9.1 Program to Connect to SQL Server DB instead of Access mdb

At my job there's a SAS script that connects to a Microsoft Access database to retrieve data to a flat file. I've been tasked with adapting it to connect to a SQL Server database instead. We have SAS 9.1 and I cannot update the version because that's not my decision. Here's the code that connects to the Access database (I've replaced the server name and folder names with generic tags for this post):
proc import out=SPONSOR
datatable="SPO_LOAD_UNBLIND"
dbms=ACCESS2000 replace;
database="\\<Server>\<Folder>\<Subfolder>\PROCESS.mdb";
memosize=2048;
run;
What do I need to do to connect this to a SQL Server database named "DM_C0000" with the same table name as in the Access database ("SPO_LOAD_UNBLIND")?
This ended up working:
proc sql;
connect to odbc (dsn=<dsn> user=<userid> pwd=<password>);
create table SPONSOR as select * from connection to odbc(select * from <database>.<schema>.<table>);
quit ;
Alternatively, you can connect to all current tables of a SQL Server database with a libname via ODBC.
* WITH DSN;
libname mydata odbc datasrc="DSN Name" user="username" password="password";
* WITH DRIVER (change driver name to your current installation);
libname mydata odbc complete="driver=SQL Server; Server=servername;
user=username; pwd=password; database=databasename;";
Just be aware changes to tables in SAS affects live database tables. Additionally, deleting entire library deletes all tables in database (not database itself). Instead, be sure to unassign libname.

MS SQL Server 2008 - Confusion in migrating from MySQL re: "select XYZ from TABLE"

So I'm just confused here.
I've got to migrate my database from MySQL to MS SQL Server 2008. I've transferred the data via the "MS SQL Data Wizard" app from SQL Maestros. It took the data+structure from my MySQL database "gk" and copied it into a database "gk" on my MS SQL Express instance.
But when I connect to the MS SQL instance and try to run an SQL query, I only get results when I execute "select * from gk.TABLENAME" or "select * from gk.gk.TABLENAME"... If I execute "select * from TABLENAME" after executing "use gk", I get:
Error: Invalid object name 'TABLENAME'
SQLState: S0002
Error code: 208
How do I make this behave "normally"? I.e., I connect to a specific database such that I don't have to explicitly tell it in which database/schema to find the table?
UPDATE:
I should specify the structure that was created by the SQL Data Wizard app. Looking at the object browser tree on the SQL Server Management Studio, there's this:
[HOSTNAME]\SQLEXPRESS (SQL Server ...)
|-- Databases
|-- System Databases
|-- gk
|...
|-- Tables
|-- TABLE1
|-- TABLE2
|-- TABLE3
... and so on.
Thanks.
-dan
In the Login Properties dialog for your user there is a "User Mapping" page where you can set the user's default schema. Setting it to "gk" (in the "gk" database) should allow you to write queries without fully qualifying the tables.
Try this, if you haven't already:
USE gk
GO
SELECT * FROM tablename
Looks like the wizard created a database called "gk", and then put all tables in a schema titled "gk".
If the tables exist in a named schema (ie, something besides the default schema of "dbo"), then you will always have to specify the schema when querying it.
NOTE:
In some situations, there is a significant performance penalty for NOT explicitly specifying the schema/owner. More significant in older versions of SQL, but still there. May not be a big enough difference to matter in your application, but still worth knowing:
Performance Impact of Procedure Calls Without Owner Qualification
Follow-up post comparing SQL 2000 results

Resources