views:

250

answers:

3

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

A: 

Try this, if you haven't already:

USE gk
GO

SELECT * FROM tablename
SarekOfVulcan
Nope, still the same problem.
DanM
A: 

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:

BradC
so is there a way to move those tables into the dbo schema?
DanM
+1  A: 

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.

Jason DeFontes