Adding dbo or Support in stores proc - sql

A colleague of mine has given me a task to ensure all table name and pages in a stored procedure contains the relevant schemas?
For example if I have a table in a database that is dbo.table1, then in a query if I have:
Select * from table1
He wants me to change it to:
Select * from dbo.table1
This is same for pages that start with Support.
What is the significance of adding in a scheme like dbo. At the start when manually writing SQL? Is it suppose to be better for performance as it seems to know where the tables even if I don't include .dbo at the start?
I'm using SQL server 2012 and its management studio.
Thank you

You may not notice the performance if you write the schema in all of your queries. If you don't specify it, the engine will look through all of your schemas in your databases ( I'm not pretty sure if the engine will check the sys schemas too ) until it finds the table you're getting the data; It's recommended as a best practice to write it because you are telling to the engine what schema need to search the table.
I hope this answer was helpful.

dbo is the schema which is used as part naming convention for tables in a mssql database
look at this post SQL Server edits the table name with dbo as prefix

Related

How to move a table from system schema to scott schema in Oracle?

In some days ago...i was converting some Large MySQL Database to Oracle 10g R2 by using Oracle SQL Developer database migration tools.But unfortunately it was migrated on system schema.but i need to it on scott schema.
After Googling i found this two links OraFAQ Forum and ASK TOM Q&A.But I cannot find any appropriate answer. Any one Can help me to do , How it is possible.
Thanks In Advance.
IIRC the MySQL backup tool spits out plain SQL. As it would be in the form of fairly vanilla SQL -- just create and insert, I guess -- it ought to be able to be run against your Oracle schema with the minimum of alteration.
Having said that, in the SQL Developer migration wizard, the second step allows you to select the target schema. If you have a connection setup to scott, why doesn't that work for you?
If the table isn't too large (dependent upon your system resources and server horsepower etc.) then you could simply rebuild the table in the desired schema with the following.
N.B. You need to be logged in as either the target schema's user (with select permission on the table in the SYSTEM tablespace) or as system:
CREATE TABLE <newschema>.<tablename>
AS
SELECT *
FROM system.<tablename>;
Then remove the original table once the new table has been created.
If the table is large then you could use DATAPUMP to export and import it into the desired schema.
Here is an article on using Data Pump for this purpose:
http://oraclehack.blogspot.com/2010/06/data-pump-moving-tables-to-new-schema.html
Hope this helps

SQL Server 2008 Query Between Databases

We are migrating database structures, so I have one database with the old structure and one database with the new structure (both on the same server). I want to write queries to copy data from one to the other. I am expecting to go table-by-table as the schema is different. How do I do this?
You need to provide more details to get a more specific answer, but in general you just use the three-part name:
INSERT INTO NewDB.dbo.TableName
SELECT <columns>
FROM OldDB.dbo.Tablename
Are you looking for a way to do this automatically for all the tables?
You can write cross database queries like so
INSERT INTO NewDatabase.Schema.Table
SELECT Column1, Column2
FROM OldDatabase.Schema.Table
you can probably use Import data under tasks.Right Click the Target DB -> Tasks ->Import Data .You can also specify the source-> target mapping here.. and also write queries

db2 Export Table SQL - No Data

I am wondering if someone knows how to export only the table SQL from a db2 database. I want a file that has the SQL to recreate the table without the data in another database environment.
I need this a query. I know db2look has the capability but, I need a query I can run in the database to do this.
Because you don't have privileges to run db2look? You're going to need SELECT privileges on the system catalog tables anyway. And depending on what you try to do, you might also need sysadm, sysctrl, sysmaint, or dbadm.
Metadata is in the SYSIBM schema. The answers here should point you in the right direction.

Move Data from Oracle to SQL Server

I would like to copy parts of an Oracle DB to a SQL Server DB. I need to move the data because the Oracle box is being decommissioned. I only need the data for reference purposes so don't need indexes or stored procedures or contstaints, etc. All I need is the data.
I have a link to the Oracle DB in SQL Server. I have tested the following query, which seemed to work just fine:
select
*
into
NewTableName
from
linkedserver.OracleTable
I was wondering if there are any potential issues with using this approach?
Using SSIS (sql integration services) may be a good alternative especially if your table names are the same on both servers. Use the import wizard via and it should create the destination tables for you and let you edit any mappings.
The only issue I see with that is you will need to execute that of course for each and every table you need. Glad you are decommissioning the oracle server :-). Otherwise if you are not concerned with indexes or any of the existing sprocs I don't see any issue in what you are doing.
The "select " approach could be very slow if tables are large. Consider writing pro*C in that case or use Fastreader http://www.wisdomforce.com/products-FastReader.html
A faster and easier approach might be to use the Data Transformation Services, depending on the number of objects you're trying to copy over.

MySQL 'create schema' and 'create database' - Is there any difference

Taking a peek into the information_schema database and peeking at the metadata for one of my pet projects, I'm having a hard time understanding what (if any) differences there are between the create schema command and the create database command for MySQL.
Are there any differences? If not, is this a rather typical pattern of behavior for relational databases (I've heard that for other databases, such as Oracle, a schema exists in a database, rather than being on the same level as a database).
Thanks!
The documentation of MySQL says :
CREATE DATABASE creates a database
with the given name. To use this
statement, you need the CREATE
privilege for the database. CREATE
SCHEMA is a synonym for CREATE
DATABASE as of MySQL 5.0.2.
So, it would seem normal that those two instruction do the same.
Mysql documentation says : CREATE SCHEMA is a synonym for CREATE DATABASE as of MySQL 5.0.2.
this all goes back to an ANSI standard for SQL in the mid-80s.
That standard had a "CREATE SCHEMA" command, and it served to introduce
multiple name spaces for table and view names. All tables and views were
created within a "schema". I do not know whether that version defined
some cross-schema access to tables and views, but I assume it did.
AFAIR, no product (at least back then) really implemented it, that whole
concept was more theory than practice.
OTOH, ISTR this version of the standard did not have the concept of a
"user" or a "CREATE USER" command, so there were products that used the
concept of a "user" (who then had his own name space for tables and
views) to implement their equivalent of "schema".
This is an area where systems differ.
As far as administration is concerned, this should not matter too much,
because here you have differences anyway.
As far as you look at application code, you "only" have to care about
cases where one application accesses tables from multiple name spaces.
AFAIK, all systems support a syntax ".",
and for this it should not matter whether the name space is that of a
user, a "schema", or a "database".
Strictly speaking, the difference between Database and Schema is inexisting in MySql.
However, this is not the case in other database engines such as SQL Server. In SQL server:,
Every table belongs to a grouping of objects in the database called database schema. It's a container or namespace (Querying Microsoft SQL Server 2012)
By default, all the tables in SQL Server belong to a default schema called dbo. When you query a table that hasn't been allocated to any particular schema, you can do something like:
SELECT *
FROM your_table
which is equivalent to:
SELECT *
FROM dbo.your_table
Now, SQL server allows the creation of different schema, which gives you the possibility of grouping tables that share a similar purpose. That helps to organize the database.
For example, you can create an schema called sales, with tables such as invoices, creditorders (and any other related with sales), and another schema called lookup, with tables such as countries, currencies, subscriptiontypes (and any other table used as look up table).
The tables that are allocated to a specific domain are displayed in SQL Server Studio Manager with the schema name prepended to the table name (exactly the same as the tables that belong to the default dbo schema).
There are special schemas in SQL Server. To quote the same book:
There are several built-in database schemas, and they can't be dropped or altered:
1) dbo, the default schema.
2) guest contains objects available to a guest user ("guest user" is a special role in SQL Server lingo, with some default and highly restricted permissions). Rarely used.
3) INFORMATION_SCHEMA, used by the Information Schema Views
4) sys, reserved for SQL Server internal use exclusively
Schemas are not only for grouping. It is actually possible to give different permissions for each schema to different users, as described MSDN.
Doing this way, the schema lookup mentioned above could be made available to any standard user in the database (e.g. SELECT permissions only), whereas a table called supplierbankaccountdetails may be allocated in a different schema called financial, and to give only access to the users in the group accounts (just an example, you get the idea).
Finally, and quoting the same book again:
It isn't the same Database Schema and Table Schema. The former is the namespace of a table, whereas the latter refers to the table definition
CREATE SCHEMA is a synonym for CREATE DATABASE. CREATE DATABASE Syntax
Database is a collection of schemas and schema is a collection of tables. But in MySQL they use it the same way.
So, there is no difference between MySQL "database" and MySQL "schema": these are two names for the same thing - a namespace for tables and other DB objects.
For people with Oracle background:
MySQL "database" a.k.a. MySQL "schema" corresponds to Oracle schema.
The difference between MySQL and Oracle CREATE SCHEMA commands is that in Oracle
the CREATE SCHEMA command does not actually create a schema but rather populates it
with tables and views.
And Oracle's CREATE DATABASE command does a very different thing than its MySQL counterpart.
there is no difference between MySQL "database" and MySQL "schema": these are two names for the same thing