I'm trying to copy a database for use in testing/developing, in SQLDeveloper I can only see the user views, the data objects are not accessible for me.
Is there anyway to copy the views only and get a dll that creates some sort of phantom structure for the data objects that are not reachable but referenced in the sql queries for those views? Problem is there are over a thousand such references,
In the example below I cannot reach the header object due too permissions,
Example:
CREATE OR REPLACE FORCE VIEW "TRADE"."EXCHANGE" ("MSGQUE", "MSGQUE2") AS
select msgque, msgque2
from head.msgqueues;
I have tryed to export the views in SQL developer but when I import it in my Oracle test database the views contain error and are unusable because the data object did not get exported in the export.sql file,
Thanks in advance
I recommend using the expdp utility to perform this. You can explicitly say to grab views and tables.
Example parfile:
SCHEMAS=SCOTT
INCLUDE=TABLE:"IN ('DEPT')"
INCLUDE=VIEW
DIRECTORY=datapump
DUMPFILE=dept.dmp
LOGFILE=dept.log
Then you can impdp that parfile into the DB you wish and you will have the TABLE and the VIEW that goes in the schema. You can modify the IN clause to grab whatever naming scheme you would need.
Related
We have some (stable) data that is saved in some generic database (database that contains a database structure and its data). To be used, this data must be re-written. Currently, we have an application that export this data to XML files to some very specific location.
We need to add this data to some databases. I know it's possible to load XML inside tables, but we'd like a direct link between the XML files and the database tables (reducing data duplication and risk of seeing people update the generated tables instead of using proper methods).
Is that possible?
Would it be very slow?
You can use SSIS to import XML files into database tables. This will work well if the xml files conform to a schema.
https://www.mssqltips.com/sqlservertip/3141/importing-xml-documents-using-sql-server-integration-services/
I needed to move out my database to another machine, but since I have very limited read access I can't leverage the backup/restore feature.
I created DDL scripts for the tables and ran them on my new VM. I then extracted the tables that I needed and have them sitting on text files. I need a way to import these files into their respective tables. Whenever I use the native import feature it creates an entirely new table with incorrectly defined value types/sizes. So I need to import directly into the tables I created with the DDL scripts.
Thanks in advance for your help.
Right click on your database node, select Tasks > Generate Scripts... .
Hit Next, select the tables you want to extract then Next.
Then click the Advanced button.
In here under General there is a line option item called Types of data to script, change this to either Data only or Schema and data, and whatever other output options works for you.
I am trying to generate a data only script for a view using SSMS Generate Scripts feature. However, even though I select Data Only, it still only generates the view definition and not the data generated by the view. Is there something else I need to do?
I'm using SSMS for SQL Server 2014.
I know this is old, but I will answer it for other people who stumble on it.
Generate Scripts -> Data Only is bugged for views.
The easiest option without searching for other stored procedures or external tools is to copy the view contents into a table. Generate Scripts -> Data Only works fine with tables.
For example,
SELECT *
INTO NEWTABLE
FROM dbo.Component
Then you can do Generate Scripts on the NEWTABLE and select Data Only in Advanced and it will work.
You can then delete the NEWTABLE.
Given that Generate Scripts still doesn't appear to work for view data as of SSMS v17.9.1, an alternative depending on your needs might be to use the SQL Server Import and Export Wizard. You can read data from a view and write it to a table, across different databases and servers without resorting to a linked server.
SSMS is still poor at this, VS has been able to do this for a while
Use menu VIEW->SQL SERVER OBJECT EXPLORER
Create a new server
Navigate down to your table or view , right click -> View Data
use the filter to limit the dataset to what you are interested in
Then use the SCRIPT command (also available on context menu)
This works for views and tables.
Not super easy, but ill give it A-. Way better than other hacks that used to be available (including SSMS.ExportData which is not great)
hope that helps someone. I just had to export some rows and had to re-remember how to do this.
hope it helps someone...
greg
I am attempting to create an indexed view on SQL Server 2008. I have a master database in which I cannot make any changes to (in terms of adding tables, views, etc.). However, I need to create some different views for various reasons that need to work with live data.
I have created a new database along side my master database so I can create views there. I am able to create views just fine, but I want to index some of the larger views. However, when I try to create a schema bound view cross-database, I receive the following error:
Cannot schema bind view 'dbo.Divisions' because name
'master.dbo.hbs_fsdv' is invalid for schema binding. Names must be in
two-part format and an object cannot reference itself.
Since I am going cross-database with the views, I have to reference the name in three-part format.
My creation statement for the view:
CREATE VIEW dbo.Divisions WITH SCHEMABINDING AS
SELECT master.dbo.hbs_fsdv.seq_ AS DivisionID,
master.dbo.hbs_fsdv.fs_division_desc_ AS Description
FROM master.dbo.hbs_fsdv
How can I create an indexed cross-database view in SQL Server?
Plain and simple. You can't. From the MSDN page:
The view must reference only base tables that are in the same database as the view.
https://msdn.microsoft.com/en-us/library/ms191432.aspx
Although (per the docs) it cannot be done directly with a simple SQL statement, this use case is very common and has a solution.
The architecture would have to involve caching the remote tables into your centralized database, and building the indexed view on top of them.
Some good notes on this can be found here:
What is the best way to cache a table from a (SQL) linked server view?
and
https://thomaslarock.com/2013/05/top-3-performance-killers-for-linked-server-queries/
When first time I created my App, I created a Database using Microsoft SQL SERVER Management Studio and I connected my App with it.
I created another DB with the same tables and every thing but with diferent names and I let my App to connect to the second one because I want to make some changes and when I am trying to edit my DataSet with Wizard I get this tables page :
as you can see my app couldn't find the right tables and when I am trying to select LastWork table as in the pic, it will make the table name in the DataSet LastWork1.
How I can fix this problem? and let it find the right tables
I've seen this problem when using copies of databases as well, after pointing to a different connection in the settings area of the project properties. The XSD evidently hard codes each DbObjectName with the name of the database and schema in use at design time. One approach to fixing it is to open the wizard for the appropriate dataset, uncheck the red-x objects with the missing references, close the wizard, then re-open it and re-select the objects that are needed. This is not ideal in a large xsd if many findby queries, custom columns, etc. have been added. So an alternative is to do a find and replace on the database name within the XSD itself.
Interestingly, my experience has been that an application runs fine when the connection string points to a differently named but otherwise identical database.