Showing posts with label names. Show all posts
Showing posts with label names. Show all posts

Thursday, March 29, 2012

Get all table names with a given column name

All, is there a way of getting all table names that contain a column
name?
I'm looking at a DB that has 125+ tables and I'm interested in finding
all table names that contain the column order_date.
How can I do it?
TIA,
SashiSelect table_name from information_Schema.columns where
column_name='column name'

Madhivanan

Sashi wrote:

Quote:

Originally Posted by

All, is there a way of getting all table names that contain a column
name?
I'm looking at a DB that has 125+ tables and I'm interested in finding
all table names that contain the column order_date.
How can I do it?
TIA,
Sashi

|||How can I do it?

One method is to query the INFORMATION_SCHEMA views:

SELECT
c.TABLE_SCHEMA,
c.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES t
JOIN INFORMATION_SCHEMA.COLUMNS c ON
t.TABLE_SCHEMA = c.TABLE_SCHEMA AND
t.TABLE_NAME = c.TABLE_NAME
WHERE
t.TABLE_TYPE = 'BASE TABLE' AND
c.COLUMN_NAME = 'column order_date'
ORDER BY
c.TABLE_SCHEMA,
c.TABLE_NAME

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Sashi" <smalladi@.gmail.comwrote in message
news:1152627046.364476.199010@.h48g2000cwc.googlegr oups.com...

Quote:

Originally Posted by

All, is there a way of getting all table names that contain a column
name?
I'm looking at a DB that has 125+ tables and I'm interested in finding
all table names that contain the column order_date.
How can I do it?
TIA,
Sashi
>

Get all SQL Server Names

hi,
can someone tell me how can i get all sql server names in my network.
thanks

You can use System.Data.Sql.SqlDataSourceEnumerator, please refer to:

http://msdn2.microsoft.com/en-us/library/a6t1z9x2.aspx

Monday, March 26, 2012

Generic staging design of data warehouse

I have a question about staging design using SSIS. Has anyone come up with an ETL design that would read table names from a generic table and dynamically create the ETL to stage the table.

1. Have a generic table which would have table name and description and whatever else that was required.

2. Have a master ETL that would enumerate through the table and stage all the table names found in the generic table.

This way I wouldn't have to create an ETL which would hardcode the names of 300-500 tables and have the appropriate 300-500 data sources and targets listed.

Not sure if I am making sense but I hope someone understands the attempt.

thanks

Assuming you know the metadata of each table this should be possible. It won't be easy - but possible.

You'll need to generate a package using code. There are examples in BOL and this post should help out - http://www.sqljunkies.com/WebLog/knight_reign/archive/2005/12/31/17731.aspx

-Jamie

|||

Thanks for the the lead.

In my case, I'm trying to read from Oracle and move the table(s) to SQL Server. I assume this would not work similarly as the task that is mentioned is only from SQL Serer to SQL Server.

|||

In Oracle, you can hit some of the system tables to generate them like all_tables and all_tab_columns to retrieve the metadata you would need to do this. Like Jamie said, it will be a lot of work to do and you'll learn a lot about the object model by doing it :).

-- Brian Knight

|||

I apologize for not being more explicit with my requirements. I already know all the Oracle tables I need which with Oracle Applications can run anywhere up to 10000 tables depending on which applications are installed.

In our staging strategy where we move our Oracle tables to SQL Server we'd like to get away from creating N number of packages or one large package with N number of tables we require which could be at least 500. The idea of having to hardcode 500 OLE DB source objects and 500 OLE DB target objects seems a little archaic at best to me. I'm just wondering if a better strategy would be to be able to access a SQL Server table where we would maintain a list of those tables required (which would include more metadata information for our own operations staff which we can't using the Oracle FND_TABLES or ALL_TABLES/ALL_OBJECTS).

We would then have one ETL job that would essentially read from this table and dynamically create the 500 OLE DB source and target objects required to complete our daily staging routines.

The prior example which Jamie eluded to seems to only work with SQL Server source and target situations. Is there some way we could accomplish this using Oracle source to SQL server target and how would I best get started on this?

thanks

|||

Yes, the example only uses SQL Server sources and targets but the theory and the approach are roughly the same. It is still just an OLE DB source so really, there isn't any difference. just a different connection string.

-Jamie

|||You could use the Import Data context menu to not only build your Staging Schema but also to build your extract package.

On the first Import Data process, link to your Oracle box and select

the tables you want to import. You can optionally set destination

column types. If you have clob/blob columns, you will have to

process them manually. Once your done setting your options, just

run the package.

On the second Import Data process select the same tables. Here is

the annoying part, for each table you need to set the option to

append. When your finished, save the package. You'll then

have an extract package for all 500 tables.

Larry Pope|||

If you know T-SQL and PLSQL well enough I'd not bother with SSIS...

Just create set of scripts based on meta-data that:

- create target table

- dumps text file with data

- load tables in SQL Server field by field (may be by using Bulk Insert)

- map data types when needed for blobs and so on

The scripts would accept a table name as parameter. Then loop through system table in Oracle Db and run that script.

I don't think SSIS transformation toolset is mature enough to do things like that...but you can use SSIS or out it all together in a workflow.

|||

I guess I don't completely understand, sorry!!! Where is the Import Data context menu?

It still sounds like much manual work. I was hoping for something more dynamic.

Sorry, for the questions but I'm new to SSIS. I have been using Business Objects Data Integrator product which is quite different in many aspects.

thanks

|||The Import Data context menu can be accessed in SQL Management

Studio. Right-Click on the destination database and select

Tasks. The option is near the bottom.

If you don't have the schema setup in your staging database, it is alot

easier to use the wizard to generate your tables. If you don't

make any changes, it should only take a few minutes to build the

schema. But the package will also copy data over as well, so if

you have data in the source it might take awhile.

As far as the amount of manual work, that's a matter of opinion.

Would you rather develop a package that can read tables/schema from

Oracle, checks tables/schemas on MSSQL and dynamically populated them

OR run through a wizard and manually set the append option on each

individual table.

There are advantages and disadvantages to both. One big advantage

to the dynamic approach is that the destination table(s) will

automatically be updated with schema changes. The big advantage

of the Import Data method, is that it will take significantly less time

implement.

Larry Pope|||

Thank you very much for the additional information and guidance. I'll take a look at your recommendations.

John

Wednesday, March 21, 2012

generating script with SMO

I am taking my table names and colums from xml file and then generating the script and executing it.I have problem creating the script for incerting table with multiple colums.Maybe the problem is that I am using a for loop to get all column names from a array string.Has anyone idea why it is not working? When I try insert of a table without loop it is wirking!Here is the code :
Server server = new Server(); // Create table in my personal database Database db = server.Databases["new"]; // Make Sure Constraint is Scripted ScriptingOptions so = new ScriptingOptions(); so.IncludeHeaders = true; so.SchemaQualify = true; // Create In-Memory Table Table newTable = new Table(db, Names[0].ToString()); for (int i = 1; i < Names.Length; i++) { Column newColumn = new Column(newTable,NamesIdea); newTable.Columns.Add(newColumn); } foreach (string s in newTable.Script(so)) /// Error generating the script { myTableScript = myTableScript + s; } db.ExecuteNonQuery(myTableScript); //disconnect form Database connection.Close();

Could you please metion the full error you are getting.

Thanks,
Kuntal

|||I fixed the problem.I haven't set the column format and that's why the script was not correctly generated.The loop is functioning now ok. Here is the edit line :Column newColumn = new Column(newTable, attr.Name, DataType.NVarChar(50));Now I can easily take the table and column names from the xml file and directly put them without using array strings.Thanks for yor time :) Have a nice day !

Monday, March 19, 2012

Generating File names on the fly

Hi,

I want to create a package that can process a flat file based on the current data. i.e. name of the file contains current date and some predefined characters.

What is the best way to process it?Use a property expression on the ConnectionString property of your FlatFile connection manager to set it to the correct filename (containing the date).

-Jamie

Friday, February 24, 2012

Generate Column List

Is it possible to generate a list of all column names in a table seperated
by a comma?
I want to do this because I am creating some triggers on a large number of
tables, with a large number of fields in each, and rather than type out my
list of fields I wanted to generate a list so I could just copy/past into my
triggers.
Thanks
Hi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.

Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>
|||Or a SELECT TOP 0 * would do ;-)
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:ugGZPWQWEHA.3988@.tk2msftngp13.phx.gbl...
Hi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.

Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>
|||Using the object browser window in SQL Query Analyzer may help you. Try it:
- Start Query Analyzer, connect to your database server.
- Click from the Menus: Tools | Object Browser | Show/Hide (or just hit F8).
This brings up the Object Browser pane.
- Navigate database object tree in Object Browser pane to table of interest.
- Right-click on that table and pick Script Object to Clipboard as Select |
Insert | Update | Delete as appropriate.
- Click in your query window and hit Control/V to paste the SQL statement.
You get a complete SQL statement with placeholders for things you will need
to supply.
A friend pointed this out to me a while back. Looks like there may be other
tricks available via the templates tab but I've not explored the
possibilities.
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>

Generate Column List

Is it possible to generate a list of all column names in a table seperated
by a comma?
I want to do this because I am creating some triggers on a large number of
tables, with a large number of fields in each, and rather than type out my
list of fields I wanted to generate a list so I could just copy/past into my
triggers.
ThanksHi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.

Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>|||Or a SELECT TOP 0 * would do ;-)
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:ugGZPWQWEHA.3988@.tk2msftngp13.phx.gbl...
Hi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.

Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>|||Using the object browser window in SQL Query Analyzer may help you. Try it:
- Start Query Analyzer, connect to your database server.
- Click from the Menus: Tools | Object Browser | Show/Hide (or just hit F8).
This brings up the Object Browser pane.
- Navigate database object tree in Object Browser pane to table of interest.
- Right-click on that table and pick Script Object to Clipboard as Select |
Insert | Update | Delete as appropriate.
- Click in your query window and hit Control/V to paste the SQL statement.
You get a complete SQL statement with placeholders for things you will need
to supply.
A friend pointed this out to me a while back. Looks like there may be other
tricks available via the templates tab but I've not explored the
possibilities.
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>

Generate Column List

Is it possible to generate a list of all column names in a table seperated
by a comma?
I want to do this because I am creating some triggers on a large number of
tables, with a large number of fields in each, and rather than type out my
list of fields I wanted to generate a list so I could just copy/past into my
triggers.
ThanksHi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.
:)
Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>|||Or a SELECT TOP 0 * would do ;-)
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:ugGZPWQWEHA.3988@.tk2msftngp13.phx.gbl...
Hi,
Simple way is:
In query Analyzer ,
Go to Tools menu -- Options -- Result Tab -- Results Output format --
Select " Comma Delimited (CSV)".
Now excute the below command in text output mode (Query menu -- click --
Results in Text):-
set rowcount 1
select * from table_name
This will give the output in comma delimited. The first row is column names.
:)
Thanks
Hari
MCDBA
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>|||Using the object browser window in SQL Query Analyzer may help you. Try it:
- Start Query Analyzer, connect to your database server.
- Click from the Menus: Tools | Object Browser | Show/Hide (or just hit F8).
This brings up the Object Browser pane.
- Navigate database object tree in Object Browser pane to table of interest.
- Right-click on that table and pick Script Object to Clipboard as Select |
Insert | Update | Delete as appropriate.
- Click in your query window and hit Control/V to paste the SQL statement.
You get a complete SQL statement with placeholders for things you will need
to supply.
A friend pointed this out to me a while back. Looks like there may be other
tricks available via the templates tab but I've not explored the
possibilities.
"Keith" <@..> wrote in message news:uuNjPFQWEHA.3664@.TK2MSFTNGP12.phx.gbl...
> Is it possible to generate a list of all column names in a table seperated
> by a comma?
> I want to do this because I am creating some triggers on a large number of
> tables, with a large number of fields in each, and rather than type out my
> list of fields I wanted to generate a list so I could just copy/past into
my
> triggers.
> Thanks
>

Sunday, February 19, 2012

Generate a SQL Script to create Indexes

I would like to put together a T-SQL script using Table A that has all of
the table names.
The T-SQL will read the table names and generate the sql statements to
indexes for these tables.
Table A will be in the same database as the tables that would like to create
the indexes. I know you can do this with SQL Server Manager from All Task-
>
Generate SQL Script, but I would like to automate this task.
Please help me with this task.
Thank You,You can find the names of all the tables and in your database in the
information_schema.tables view, and all the columns in the
information_schema.columns view.
Jacco Schalkwijk
SQL Server MVP
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:5DD35EDB-0634-4A66-B4EE-04FDBD467BB4@.microsoft.com...
> I would like to put together a T-SQL script using Table A that has all of
> the table names.
> The T-SQL will read the table names and generate the sql statements to
> indexes for these tables.
> Table A will be in the same database as the tables that would like to
> create
> the indexes. I know you can do this with SQL Server Manager from All
> Task->
> Generate SQL Script, but I would like to automate this task.
>
> Please help me with this task.
> Thank You,
>|||Joe
You create an index on the column not on the Table. You have to know all
columns that you want to create an index. It is really important because if
you create redundant index or useless index it may lead to performance hit
of the query.
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:5DD35EDB-0634-4A66-B4EE-04FDBD467BB4@.microsoft.com...
> I would like to put together a T-SQL script using Table A that has all of
> the table names.
> The T-SQL will read the table names and generate the sql statements to
> indexes for these tables.
> Table A will be in the same database as the tables that would like to
create
> the indexes. I know you can do this with SQL Server Manager from All
Task->
> Generate SQL Script, but I would like to automate this task.
>
> Please help me with this task.
> Thank You,
>