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

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

Related

there a way to drop 'sysmessages' table from one database?

unfortunately i create table call 'sysmessages' in SQL Server 2008. when i restore the DB to SQL Server 2012 i realize that i have two Tables call 'sysmessages'.
i don't want to change my table name because it using in the code.
can i remove only from specific database system table?
it is not a table, but a view
of course you cannot remove it, but you don't need to. It is in a different schema. You will not address it like select * from sys.sysmessages, you will address it like select * from dbo.sysmessages
"i don't want to change my table name because it is used in the code" - you can/should change the code as well :)
edit - no. 2. is not applicable in SQL 2012, however it is tested and working in SQL 2008R2
You cant drop system tables,your best bet is to change your code

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

generate create table from existing table

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

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;

access: getting create table string

i have a table in access and i would like to get the SQL string from it that will generate the table like:
CREATE TABLE example (
id INT,
data VARCHAR(100)
);
is there any way to do this?
I don't believe there is a built in way. You will have to use a third party tool to convert the schema:
DBWScript
MDBScript
To run a VB Script to convert the tables there is on here:
Table Creation DDL from Microsoft Access
If you are talking about a generic method that will work on any Access table I don't know of any way to get a SQL CREATE table statement directly. I suspect there are too many features in Access (drop down values for fields, input masks, etc.) that don't translate well to SQL.
Access does have the ability to export the table directly to SQL Server however. You could try to push the table to SQL Server and then generate the CREATE statement from that.
If you're trying to port this to SQL server or the like, I think you'll have to build the scripts by hand.
You could always use the SQL server import wizard (or the export to SQL from Access) to move it over, then create the scripts in SQL server.
Don't forget, you can usually get SQL Express for free, so that's a way to do things.
May be exporting the tables to XML/XSD? It's not DDL but you have the schema in a file that you can import using other tools.
More or less as you have it:
CREATE TABLE example (
id INT,
data text(100)
);
You may wish to check out DAO data types: http://allenbrowne.com/ser-49.html