Create and copy a table from one SQL database to another - sql

Let's say I have a production database and a development database.
The CUSTOMER_PERMISSIONS table is created and populated in the development database.
What is the best way to create and copy the CUSTOMER_PERMISSIONS table to the production database?
INSERT INTO CUSTOMER_MARKET_PERMS
SELECT * FROM indeiso.dbo.CUSTOMER_MARKET_PERMS
returns
INSERT INTO CUSTOMER_MARKET_PERMS
SELECT * FROM inukiso.dbo.CUSTOMER_MARKET_PERMS
Error at Command Line:668 Column:25
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
I am using Oracle 12 database system, and i am not sure why it is throwing this error

on the prod server you can do a query like this:
INSERT INTO CUSTOMER_PERMISSIONS
SELECT * FROM [devserver].dbo.CUSTOMER_PERMISSIONS

If you're okay with not using a query, and in case you happen to be using MSSQL Server, why not use the import/export wizard?
Right-click the database you want to export from, then select TASKS -> Export Data. From there, follow the wizard.

Are you sure that you have two different Oracle databases? If so then you need to setup a database link between the two databases. If I were you I should first make sure that you from the production database can select the data in the development database. If you can that and the two tables are identical then I can't see way your statement is not working.

Related

SSIS not updating table after insert

I have an SSIS package that sends data from SQL 2014 to an Oracle 11G DB. No issues connecting or transferring the data to Oracle but it fails when updating the source SQL tables. SSIS give ORA-00971:missing SET keyword
Based on the below why would Oracle be looking for a SET keyword? The update statement is on the SQL database
I've switch connections to reflect the SQL tables (errors resolving the Oracle table names then)
UPDATE INTERFACE.dbo.TURN
SET INTERFACE.dbo.TURN.DUPLICADO =
INTERFACE.dbo.TURN.DUPLICADO + 100
WHERE EXISTS
(SELECT
*
FROM [REMOTEORA]..[REMOTEORA].[TURN_BALANCE] BO
WHERE BO.[TURN_BALANCE].[ID_TURN]=INTERFACE.dbo.TURN.N_TURNO AND BO.
[ID_PLACES]
= INTERFACE.dbo.TURN.ID_LUGAR AND
BO.DT_CLOSE =INTERFACE.dbo.TURNO.FIN_TURNO)
AND (INTERFACE.dbo.TURN.DUPLICADO < 100)
First changing the connection for the updating piece to the SQL server resolved the ORA error but the updates were still failing and calling TURN_BALANCE a column. Altering the table alias to four letters (BOYO) vs the two (BO) completely resolved the issue

Inability to run an SQL statement with a "with" statement in Excel

I am trying to run SQL through excel and I have the following SQL query within the data connection:
WITH TEST_DB as (select * from TEST_ADM.KPI_SAMPLE_TEST)
SELECT DISTINCT
BASE.YEAR_MONTH AS YEAR_MONTH
FROM TEST_DB BASE
If I try running this with SQL Developer, it will run successfully, no problems but when I try to run it in Excel, I get the message:
The query did not run, or the database table could not be opened.
Check the database server or contact your database administrator. Make sure the external database is available and hasn't been moved or reorganised, then try the operation again.
Is there some sort of limitation within Excel that prevents me from using WITH statements?
If I remove the statement and select from the table directly, it works but I need to use the WITH data table 6 times in my code and its rather long.
Oh, the database is an oracle database.

Use a specific database and table in MSSQL (Visual Studio)

I am working in Visual Studio and using the SQL manager built into the studio. Now I am connecting to several databases and I would very much like to be able to save and open my SQL queries and still have them access the correct database and table.
So:
Database servers:
db.company.com
databasenumber1
databasenumber2
databasenumber3
db2.company.com
databasenumber1
databasenumber2
databasenumber3
db3.company.com
databasenumber1
databasenumber2
databasenumber3
Now I wish to write an sql query that does something simple, lets say:
select * from users where userid = '12';
However I want to select this from database server db2 and from database databasenumber3.
How do I write that in a use statement? Or is there something other than "use"??
Working among several databases in once script file requires USE followed by GO statement.
USE db1;
GO
SQL statements ...
...
USE db2;
GO
SQL statements ...
...
Another option is to use server.dbname.tablename format but that strictly requires that all of your databases are hosted on same server.
SELECT * FROM server.db1.table1
SELECT * FROM server.db2.table2
...

Can I create a view that will query a table from another sql server on another server but same domain

I need to query a table from another SQL Server on a different server but same domain, but I am not sure how I will be able to do it.
I tried solution given in this answer Can I create view in my database server from another database server but it doesn't work for me as I got SQL Server 2000 (please don't hate :-) ).
When I try solution given then i get this error,
Line 23: Incorrect syntax near '-'.
which is because command is not compatible with SQL Server 2000.
Edit
SELECT * FROM AnotherServer.AnotherServerDatabase.Server.Table1
you can link the servers and run cross server queries as long as you put the server name before the DB your running the query on.
For example
SELECT * FROM "linkedserver".dbo.aTable
(without "" marks )
bear in mind different server versions though. I run cross server queries from 2008 to 2000 servers and its a pain adapting :)

how can i copy table and data from one database to another using oracle

I'm using Oracle PL/SQL developer. I have two databases live and dummy.
I have been using the dummy database for development and now i need to add all the new tables and data into the live database without effecting the data currently stored in it.
I also need to copy over all the new sequences and triggers.
I've tried exporting a table but had no luck and using the SQL view i only get the SQL for the creation of the data and not the data it contains.
I also found this SQL code
COPY FROM test#DUMMY - CREATE test -USING SELECT * FROM test;
But it asks me for a name and password of which I dont know and then fails after 3 attempts. It then goes on to say there is a syntax error as well.
I'm still fairly new to using Oracle and any help would be appreciated.
You can do that using datapump.
or if you want to copy from schema to schema
create table shecma2.old_table
as
select * from schema1.old_table
or using oracle sql developer - here is link.
Try:
CREATE TABLE NEWTABLE AS SELECT * FROM OLDTABLE;