generate create table from existing table - sql

I have a few large tables in a oracle DB (lots of columns and data types) that I need to move to another oracle database (say from my DEV region to UAT region). Is there anyway I can get sql developer or sql plus to output a create table statement that is exactly the structure of the existing table?
thanks

If you want to get it through SQL statement then you can try the below query
SELECT dbms_metadata.get_ddl('TABLE', 'Your_Table_Name') FROM dual;
See DBMS_METADATA for more information.
You can generate the script using Toad software as well (In case you have Toad installed)

If you are making use of the SQL Developer you can right click the table that you want to generate a script for.
From there select Quick DDL and then click on Save To File. This will then generate the create table script to an external sql file. You can do this for multiple tables as well by selecting more than one table at a time.
Hope this helps!!

Another option is to create a database link between the two schemas and then do a
create table table_name AS SELECT * from table_name#original_server

Related

Dropping and recreating database, along with tables

I have a database whose structure I'm happy with, but which has a fair amount of dummy data in it. I would like to drop and recreate the database while at the same time wiping out the tables, but retain the table structures and relationships.
When I right-click on the database and choose to script 'drop and create' statements they're for the database itself, but no mention of the tables within-- unless I'm missing something.
Is it possible to generate a script that drops/creates a database and the tables within? I can individually select each table and script out their drop/create statements and order things so it will work, but are there other ways of doing this in one swoop?
I have a localized version of Sql Server 2008 R2, so some of my instructions could be imprecise.
I hope that there are no big differences.
Right click on your database and select Tasks and then Generate Scripts
Leave the first option selected (Build script for all db and objects) and select next
On the second page click Advanced
Select the option to Build Script for DROP & CREATE
Select the option to Use only the Schema (not Schema and Data)
Check the other options you would like to use.
Finally choose your save options and click Next until SSMS creates the script
Instead of that you should do this. That way you can select different tables or stored procedure to script for. See MSDN How to: Generate a Script (SQL Server Management Studio) on how to do it step-by-step.
Right click on DB_Name -> select tasks -> Generate Scripts

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;

Generate Scripts of Certain Columns from a table in SQL Server 2008 management studio

I have a SQL Server 2008 database. This database has a table with 6 columns in it. I want to generate the insert scripts associated with the data only. I know how to do this part with SQL Server management studio via the "Advanced" dialog in the "Generate Scripts..." wizard. My challenge is, I only want to script 5 of the 6 columns. How do I do this?
Check out the FREE SSMS Tools Pack v2.0 - it has among a lot of other things a feature to generate INSERT statements for data in your tables, and yes - you can pick for which columns that INSERT statement should be:
SELECT Column1,Column2,Column3,Column4,Column5
INTO new table
FROM your Existing table;
This will create a new table with the columns that you specified, then the data will be inserted in the new created table. Then script the new table that have only the five columns that you want.
I don't think there's a way to do this. After you generate the full table script, you can do one of a few things.
If you want to preserve the actual field (keep it there), then just do something like:
update yourTable
set yourColumnThatYouDidntWantDataFor = null
Or, if you didn't want that field to be in the table at all, you can just drop it like so:
alter table yourTable
drop column yourColumnThatYouNoLongerWant

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

How to generate "Create Table" script, when I only have read only permission?

I have read only permission on a SQL Server 2005 database, and I'm looking to get a table schema locally to work with. With my current access it won't let me right click on the table and choose 'Create Table' to get the script for this.
Is there a way to generate the create table script from a select statement or by some other mechanism?
Thank you!
You could create a linked server on your local machine. Then, you can use select ... into to copy the table, including data:
select *
into NewTableName
from [LinkedServerName].[DatabaseName].dbo.TableName
This will not copy indexes or constraints. To exclude the data, use select top 0 *.
It's a bit long but the script in Script Table Definitions using TSQL could be addapted to work without needing to create the stored procedure mentioned.
I am assuming you are working with SQL Server 2005