Copy or create an SQL table in windows mobile services from Windows Store App - sql

In "regular" SQL, we can create tables by sending queries like:
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)
... and can copy tables as such:
CREATE TABLE new_table AS (SELECT * FROM old_table);
Now skip over to the Windows Azure Mobile Services world, and its "special" SQL. I am having good success creating tables using the Azure portal (non-programmatically) and then accessing these tables as such:
var mobClient = new MobileServiceClient("[url]", "[app key]");
var mobTable = mobClient.GetTable<MyTableClass>();
Browsing the intellisense for the client showed no options for create or copy table.
Is it possible in Windows Azure Mobile Services, and its unique brand of SQL, to create new tables or copy existing ones, programmatically from the app? Anyone know how?
Thank you.

I actually found out on msdn from Microsoft that this is not possible with Azure today. I submitted it as a feature request.
One nice feature, which I have been using, is the dynamic schema. If you have a table definition class in your project in Visual Studio, whose name matches an Azure table, when you make a change to your VS class, the Azure SQL table updates automatically. You still have to double check and fine tune things, but is still handy.
You enable dynamic schema on this page:

can you not send the SQL via the mssql object?

Related

Data Migration Assistant - Cross-database queries

I am running an assessment using the Azure SQL Data Migration Assistant (3.4.3948.1). In my initial assessment, I had a function that was calling fn_varbintohexstr so I fixed it (read removed the function). I also deleted all our synonyms.
Now I run the assessment more times and it continues to give the 'cross-database queries' error but without listing any more specifics. How can I find out what particular objects it means? Or is it possible that it has somehow cached my result and I need to invalidate it somehow?
This means you have programming objects in that database that reference another database. For example a query like this:
SELECT * FROM Database1.dbo.Table1
One of the options you have is to import those external objects to your database and change the three and four-part name references that SQL Azure does not support.
You can also use CREATE EXTERNAL DATA SOURCE and CREATE EXTERNAL TABLE on SQL Azure to query tables that belong to other databases that you have to migrate to SQL Azure too.

How to create a new table from existing table with both keys and data in SQL Server 2012 (Management Studio)?

How can I create a new table from an existing one in SQL Server 2012 , with both its keys and its data ?
This :
select * into New_Table
from Old_Table
Does not create the dependencies .
And this :
In Sql Server Managment Studio, right-click your existing table and
select Script Table as > Create to > New Query Editor Window
Doesn't get the data .
Thanks
The following instructions work well if you want a GUI based solution and are dealing with a moderate amount of data.
In SSMS, right-click on the database that contains the table and select Generate Scripts
Select the specific table(s) to recreate
Select the Save to new query window radio button and click Advanced to set scripting options for the table
Set the Types of data to script property to Schema and data
Modify the table name in the resulting script as appropriate
One way is to use something like SQL Server Data Tools (SSDT). This is a free, Microsoft, add-on to Visual Studio 2012/2013 (which you don't need to own). This tool will do schema and data compares. So all dependencies and schema objects will be created for you, in the correct order.

how do i read Visual foxpro Database as External table in oracle 10g database?

I have couple of vfp 9.0 .dbc and .dbf files i am trying to setup these tables as external tables,
but from information i googled it seems like that oracle only support .CSV files
is that even possible
I will be selecting,updating,deleting,inserting a few rows in the dbf files.
for example
create or replace directory ext_tab as 'C:\EXT_TAB';
CREATE TABLE ext_test(
CODE NUMBER(4), DESC CHAR(20)
ORGANIZATION EXTERNAL(
TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
NOBADFILE
NOLOGFILE
SKIP 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(CODE INTEGER EXTERNAL (4),
DESC CHAR(20))
)
LOCATION ('ext_tab_test.dbf')
)
PARALLEL
REJECT LIMIT 0;
any correction, guidance, article is much appreciated.
I don't know about the physical layout of a visual fox pro database file but I have no doubts that it has the ability to use odbc connections. If that is the case you can use dg4odbc to create a connection from oracle to that database and use the tables in the way you want.
Having the fox pro files as external tables is not going to help you.
dg4odbc is part of the regular oracle installation. It comes down to finding a odbc driver, install that, create a odbc.ini with the details for your fox pro database. Next create a listener entry in your oracle listener with dg4odbc as program. Next create a tnsnames.ora alias that points to the listener entry that has (HS=ok) in the description. In $ORACLE_HOME/hs/admin you create a init{ODBC_NAME}.ora that is used by dg4odbc to tie the pieces together.
If all that is in place you can create a database link from oracle to your fox pro database using the tnsalias created above.
I used to use Visual Foxpro 9 to query an Oracle 10g database in one of our applications.There are a couple ways to do this:
Visual Foxpro SQL pass through
or
Visual Foxpro Remote Views
Since you are already using a Visual Foxpro Database container (.DBC), you might want to look at the Remote View method. I've used both methods. They both work well.

SQL Azure - copy table between databases

I am trying to run following SQL:
INSERT INTO Suppliers ( [SupplierID], [CompanyName])
Select [SupplierID], [CompanyName] From [AlexDB]..Suppliers
and got an error "reference to database and/or server name in is not supported in this version of sql server"
Any idea how to copy data between databases "inside" the server?
I can load data to client and then back to server, but this is very slow.
I know this is old, but I had another manual solution for a one off run.
Using SQL Management Studio R2 SP1 to connect to azure, I right click the source database and select generate scripts.
during the wizard, after I have selected my tables I select that I want to output to a query window, then I click advanced. About half way down the properties window
there is an option for "type of data to script". I select that and change it to "data only", then I finish the wizard.
All I do then is check the script, rearrange the inserts for constraints, and change the using at the top to run it against my target DB.
Then I right click on the target database and select new query, copy the script into it, and run it.
Done, Data migrated.
Since 2015, this can be done by use of elastic database queries also known as cross database queries.
I created and used this template, it copies 1.5 million rows in 20 minutes:
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<password>';
CREATE DATABASE SCOPED CREDENTIAL SQL_Credential
WITH IDENTITY = '<username>',
SECRET = '<password>';
CREATE EXTERNAL DATA SOURCE RemoteReferenceData
WITH
(
TYPE=RDBMS,
LOCATION='<server>.database.windows.net',
DATABASE_NAME='<db>',
CREDENTIAL= SQL_Credential
);
CREATE EXTERNAL TABLE [dbo].[source_table] (
[Id] BIGINT NOT NULL,
...
)
WITH
(
DATA_SOURCE = RemoteReferenceData
)
SELECT *
INTO target_table
FROM source_table
Unfortunately there is no way to do this in a single query.
The easiest way to accomplish it is to use "Data Sync" to copy the tables. The benefit of this is that it will also work between servers, and keep your tables in sync.
http://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started-sql-data-sync/
In practise, I haven't had that great of an experience with "Data Sync" running in production, but its fine for once off jobs.
One issue with "Data Sync" is that it will create a large number of "sync" objects in your database, and deleting the actual "Data Sync" from the Azure portal may or may not clean them up. Follow the directions in this article to clean it all up manually:
https://msgooroo.com/GoorooTHINK/Article/15141/Removing-SQL-Azure-Sync-objects-manually/5215
SQL-Azure does not support USE statement and effectively no cross-db queries. So the above query is bound to fail.
If you want to copy/backup the db to another sql azure db you can use the "Same-server" copying or "Cross-Server" copying in SQL-Azure. Refer this msdn article
You could use a tool like SQL Data Compare from Red Gate Software that can move database contents from one place to another and fully supports SQL Azure. 14-day free trial should let you see if it can do what you need.
Full disclosure: I work for Red Gate Software
An old post, but another option is the Sql Azure Migration wizard
Use the following steps, there is no straight forward way to do so. But by some trick we can.
Step1 : Create another one table with the same structure of Suppliers table inside [AlexDB], Say it as SuppliersBackup
Step2 : Create table with the same structure of Suppliers table inside DesiredDB
Step3 : Enable Data Sync Between AlexDB..Suppliers and DesiredDB..Suppliers
Step4 : Truncate data from AlexDB..Suppliers
Step5 : Copy data from AlexDB..SuppliersBackup to AlexDB..Suppliers
Step6 : Now run the sync
Data Copied to DesiredDB.
If you have onprem version that has the sp_addlinkedsrvlogin, you can setup Linked Servers for both source and target database then you can run your insert into query.
See "SQL Server Support for Linked Server and Distributed Queries against Windows Azure SQL Database" in this blog: https://azure.microsoft.com/en-us/blog/announcing-updates-to-windows-azure-sql-database/
Ok, i think i found answer - no way. have to move data to client, or do some other tricks. Here a link to article with explanations: Limitations of SQL Azure: only one DB per connection
But any other ideas are welcome!
You can easily add a "Linked Server" from SQL Management Studio and then query on the fully qualified table name. No need for flat files or export tables. This method also works for on-prem to azure database and vice versa.
e.g.
select top 1 ColA, ColB from [AZURE01_<hidden>].<hidden>_UAT_RecoveryTestSrc.dbo.FooTable order by 1 desc
select top 1 ColA, ColB from [AZURE01_<hidden>].<hidden>_UAT_RecoveryTestTgt.dbo.FooTable order by 1 desc
A few options (rather workarounds):
Generate script with data
Use data sync in Azure
Use MS Access (import and then export), with many exclusions (like no GUID in Access)
Use 3-rd party tools like Red Gate.
Unfortunately no easy and built-in way to do that so far.
I would recommend SSMS SQL Server Import and Export feature. This feature supports multiple connection configurations and cross-server copy of selected tables. I have tried .NET Sql Server connector, which works very well for the Azure SQL databases.

Copying production database setup to development database

I am using Oracle 9i, Please suggest how can I select data from one remote database and insert the data in the local database?
Also suggest how the data can be copied from a remote to remote database.
You need to create a database link.
Please refer to this link: http://download.oracle.com/docs/cd/B10501_01/server.920/a96521/ds_concepts.htm#12354
excerpts:
example:
CREATE DATABASE LINK sales.us.americas.acme_auto.com CONNECT TO scott IDENTIFIED BY tiger USING 'sales_us';
query:
For example, using a database link to database sales.division3.acme.com, a user or application can reference remote data as follows:
SELECT * FROM scott.emp#sales.division3.acme.com; # emp table in scott's schema
SELECT loc FROM scott.dept#sales.division3.acme.com;
Based on the vagueness of the question. Make a backup of production and restore it in development.
If you are talking Microsoft SQL then you can create a Linked Server. Here is an article about doing this in SQL 2008, but you can do it in earlier versions as well. Then you can select from it using a four part name LinkedServer.database.schema.table
http://msdn.microsoft.com/en-us/library/ff772782.aspx
Define a link from the development server to the prooduction server. You can then use a select based insert to copy data into the development server.
Use the SAMPLE clause on the select to retrieve a percentage of the data. For child tables use a WHERE exists clause to copy child rows for which the parent was sampled.