How to access sysobjects and syscolumns on a different database?

I'm attempting to write a script that iterates over all tables and their columns in all databases resident to a SQL Server connection. I can do either of these but cannot figure out how to merge the two together. The problem is that at the time that the
table/column information is collected, it comes out of the system tables of the current default database and I can't quite figure out how to change default databases in a way that is acceptable under the current conditions. I can't create and write to the
many database new stored procedures to handle the changing of default database and I don't want to use undocumented functions.
 but am having trouble prizing the information out of sysobjects, syscolumns and systypes on databases that are not currently the current database in use in order to find all occurrences of some string in all databases, no matter what table or
column that string resides. One of the things making it harder is that I do not want to generate stored procedures on the fly and add them to the databases being probed so everything has to be accomplished either directly or by executing a sql string.
There are two obvious approaches to the problem -
1) Change the current database (Like 'use @DBNameVar' only something that actually works)
2) Directly access sysobjects, syscolumns and systypes in a different database
Here's what I have so far - I have figured out how to make a cursor that will list all of the databases and can load that database name into a string variable and I know how to get a listing of all of the tables and columns within a database. I have another
piece of script that does a great job of probing all of the columns in all of the tables for a string.
Will the systables allow access if their database is not the current database? If so, what is the syntax? Can you show me what I need to do in my table/column iteration script? Assume, for example, that @DBNameVar contains the name of the database that needs
to be probed. What is the syntax that will combine that database name with the following script which lists all of the tables/column?
DECLARE cCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT
'[' + usr.name + '].[' + tbl.name + ']' AS tblName,
'[' + col.name + ']' AS colName,
LOWER(typ.name) AS typName
FROM
-- How can a sysobjects from another database be specified????
sysobjects tbl
INNER JOIN(
syscolumns col
INNER JOIN systypes typ
ON typ.xtype = col.xtype
ON col.id = tbl.id
LEFT OUTER JOIN sysusers usr
ON usr.uid = tbl.uid
WHERE tbl.xtype = 'U'
AND LOWER(typ.name) IN(
'char', 'nchar',
'varchar', 'nvarchar',
'text', 'ntext'
ORDER BY tbl.name, col.colorder
Richard Lewis Haggard

In addition to Latheesh and Tom solutions, I modified your code to use dynamic sql. It's just a different solution:
--first create table
CREATE TABLE tbl ( tblName sysname, colName sysname, typName sysname ) ;
GO
--now populate it with dynamic sql
DECLARE @sql NVARCHAR(max) = N'';
; WITH db AS (
SELECT name
FROM sys.databases
SELECT @sql = @sql +
N' INSERT dbo.tbl ( tblName, colName, typName )
SELECT
QUOTENAME(usr.name) + ''.'' + QUOTENAME(tbl.name) AS tblName,
QUOTENAME(col.name) AS colName,
LOWER(typ.name) AS typName
FROM
-- How can a sysobjects from another database be specified????
' + QUOTENAME(db.NAME) + N'.sys.sysobjects tbl
INNER JOIN(
' + QUOTENAME(db.NAME) + N'.sys.syscolumns col
INNER JOIN ' + QUOTENAME(db.NAME) + N'.sys.systypes typ
ON typ.xtype = col.xtype
ON col.id = tbl.id
LEFT OUTER JOIN ' + QUOTENAME(db.NAME) + N'.sys.sysusers usr
ON usr.uid = tbl.uid
WHERE tbl.xtype = ''U''
AND LOWER(typ.name) IN(
''char'', ''nchar'',
''varchar'', ''nvarchar'',
''text'', ''ntext''
ORDER BY tbl.name, col.colorder ;
' + NCHAR(13)
FROM db ;
PRINT @sql ;
EXEC ( @sql );
SELECT *
FROM tbl ;
sqldevelop.wordpress.com

Similar Messages

  • Equivalents of SQL Server sysobjects and syscolumns

    I'm developing some software that nees to work on both SQL Server and Oracle.
    Just starting on the Oracle version, and the first thing I nede to do is query system tables for the names of tables, columns, datatypes etc.
    Can anyone tell me what tables are Oracle's equivalent of SQL Server's sysobjects and syscolumns?
    Thanks

    To list all the tables belonging to the USER
    SELECT Table_Name from User_Tables;
    To list the columns for the tables (USER)
    Select column_name from User_Tab_columns ;
    Also, take a look at the following (you can repalce ALL with USER)
    ALL_TABLES
    ALL_TAB_COLUMNS
    ALL_VIEWS
    ALL_OBJECTS
    ALL_SOURCE
    ALL_TRIGGERS

  • How to access RT and CRT tables

    Hi experts can any one guide me how to view RT and CRT Tables.
    How to access RT and CRT tables.
    Is there any Tcode existing to access these.
    Thanks in advance
    Regards
    vamsi.

    Hi Vamsi,
    1) You can use the function module : CU_READ_RGDIR
    In this function module you can pass PERNR and you can get SEQNR(Sequence No) or you can take the sequence no from any transparent table also.
    2)After getting the sequence NO Pass the employee NO and Sequence NO in the function module : PYXX_READ_PAYROLL_RESULT.
    From this function module you can get the RT,BTand CRT Table results.
    Thanks and Regards
    Partha

  • Is VOFM Access key and Developer Key are different

    is VOFM Access key and Developer Key are different
    Please help me on this

    Developer key is user-specific which gives a particular user the developer rights, such as program creation/modification. It is enough to enter the developer key only once for a user.
    On the other hand VOFM/ Object key is object-specific which can be used to edit a SAP standard program Or create a new program in SAP name space(in case of routines).
    Both keys can be registered and obtained from Service Market Place.
    Regards
    Karthik D

  • How to accessed,created and modified date of particular file in java

    Hi,
    I am facing one problem.
    I know how to get the modified date/time of file in java.
    but i don't know how to find created and accessed date/time of file in java.
    Thanks,
    Tejas

    I guess thats not possible in in Windows.
    But if u r trying it on a unix machine.
    You can use Runtime class to call exec on the command
    ls -l filename
    and then store the result in a file . And then take out the last modified time. But you cant get created time.
    Thats a clumpsy way i believe.

  • How to access date and time of compiled forms

    hi all
    i want to access the date ,time and size of compiled forms that are stored in a particular folder.
    can anybody tell me how to access it.
    thanx
    Message was edited by:
    new.oradev

    hi all
    i want to access the date ,time and size of compiled
    forms that are stored in a particular folder.
    can anybody tell me how to access it.
    thanx
    Message was edited by:
    new.oradevIs this an Oracle Forms question???
    You can always use your operating system to check the creation/modification/access dates of a file on your file system.
    If you're looking for versioning, I suggest you read abot OSCM (Oracle Software Configuration Manager)
    Tony

  • How  to access data in AS 400 from Oracle database

    Hi
    Could you please help me on accessing data in AS 400 from Oracle database? what are the main things to do? Any private documentation or any oracle metalink note please...

    Hi
    Please find the details given below....Any body can help me on this please....
    Issue Description: The stock status report to be developed at SATN has some information that is currently calculated and stored in the Fox/pro system. A real time ODBC needs to be done to the AS/400 system to retrieve values for the respective fields. This has never been tested before as it impacts many areas.
    The DBA team need to work to establish such a relationship and a report needs to be written in Oracle to have this tested on a real time basis. Mapping needs to be developed on the Oracle side to grab the correct fields

  • How to set SMB and FTP sharing for different users?

    In Tiger FTP and SMB sharing was different options with their own settings each other. In Leopard there if i enable user for sharing, it enables for all protocols together.
    Another problem. In file sharing i can add shared folder, but what's sens of it, if the whole filesystem is shared (at least FTP and AFP, not SMB, thanks god) and there's no way to remove this share. Just shortcut? How can i create ftp sharing, allowing user to see only his folder, not the whole filesystem?
    Any advices are pleased, except to get Leopard Server Thank you.

    OS X Client FTP implementation is not comprehensive at all. Apple does not make FTP serving a priority for OS X (on the general principle that it is not really necessary for most consumers). Thus, by default you can't enable/disable FTP for individual users. Nor can you create FTP only users.
    However, a useful product called [Pure-FTPd|http://www.pureftpd.org/project/pure-ftpd], provides the missing functionality for free to all UNIX based systems. Even better, [PureFTPd Manager|http://jeanmatthieu.free.fr/pureftpd> provides a GUI on OS X for managing it.
    This product is probably overkill for a single-user situation - but it is a great example of leveraging the UNIX platform of OS X to significantly enhance file sharing capabilities to server level.
    Cheers,
    Rodney

  • How to show master and detail tables in different pages?

    Hi,
    Can somebody expalin me how to include or bind the master and detail tables to different pages which are included at runtime.
    thnaks,
    Naresh.

    Hello!
    you have ti create a Master/Detail data structure.
    In the first page drag the master table, on the second drag a detail table.
    It should work out of the box. Selecting a record on the master table selects
    the details on the detail table automatically!
    regards,
    Mario Udina

  • How to access two entity managers from two different servers?

    Hello
    My test programm is trying to access two glassfish application servers (gf 2.1). The code base of these servers is the same, the persistence layers are just accessing different databases -> one ist the staging/test system, the other the live server.
    After setting the connection and obtaining the em via the class persistence i can not fetch the em from the other system.
              properties.setProperty("org.omg.CORBA.ORBInitialHost", "host1");
              properties.setProperty("org.omg.CORBA.ORBInitialPort", "port1");
                    InitialContext ctx = new InitialContext(properties);
              entityManagerFactory1 = Persistence.createEntityManagerFactory("pu/refdata");               
              entityManager1 = entityManagerFactory.createEntityManager();After that Persistence seems to have been bound to host1 forever, so i can not fetch a reference to the em of host2. There is another createEntityManagerFactory method accepting a map but i dont find any reference for the properties, maybe that would help - dont know.
    Regardless of what i do, any further call to Persistence.createEntityManagerFactory returns the handle of entityManagerFactory1.
    Regards

    I want to use the EntityManagers bound to the DataSources provided by different app servers.
    Below you find an example persistence.xml with three entries. 1 & 2 have the same jta data source, 3 is different.
    My point is that Persistence binds the new factory in a wrong way if the jta data source String has already been resolved.
    If a progamm sets connection properties for app server 1 and fetches an entityManagerFactory for pu/refdata_Live, then sets connection properties for app server 2 with pu/refdata_Test they get different factory instances bound to the same server, in this case app server 1.
    If i know set the connection properties for app server 3 with pu/refdata3 Persistence sees that the jta data source "dbc/ref3" has not yet been resolved and tries to connect to the app server 3. Which it should have done for app server 2 too.
    <persistence-unit name="pu/refdata_Live" transaction-type="JTA">
         <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/ref</jta-data-source>
        <properties>
          <property name="toplink.ddl-generation" value="none"/>
        </properties>
      </persistence-unit>
        <persistence-unit name="pu/refdata_Test" transaction-type="JTA">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/ref</jta-data-source>
        <properties>
          <property name="toplink.ddl-generation" value="none"/>
        </properties>
      </persistence-unit>
        <persistence-unit name="pu/refdata3" transaction-type="JTA">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/ref3</jta-data-source>
        <properties>
          <property name="toplink.ddl-generation" value="none"/>
        </properties>
      </persistence-unit>

  • Offline database and generating objects to different databases

    I created an offline database with my objects, I can change them and push them back to the DB I got them from, but I cannot figure out how to push changes to a different database. I see where I can push to a different schema. I want to use the offline DB to maintain all my tables, and push the changes to a Test, Stage, QA DB's when I want but cannot find where to push the changes to a different database.

    I created an offline database with my objects, I can change them and push them back to the DB I got them from, but I cannot figure out how to push changes to a different database. I see where I can push to a different schema. I want to use the offline DB to maintain all my tables, and push the changes to a Test, Stage, QA DB's when I want but cannot find where to push the changes to a different database.

  • How to access music and playlists on the same computer, for both Microsoft accounts?

    Hello all,
    My husband and I recently got a new computer and are running Windows 8.1. We were able to successfully use an external hard drive to transfer all of the music and playlists over so that I can access them on my user account (I am the "main" user). All of my playlists are present exactly as they were previously. This is the location of the iTunes media folder on our hard drive: C:\Users\Brittany\Music\iTunes
    However, when my husband logs on as a user separately, the iTunes program is there, but we are only able to get him very limited access to some music. We can't get him access to any of the playlists, which is where the bulk of the music is.
    We've tried everything. We've double-checked that he's an Administrator. We've made sure that all the folders are shared between us. We can both read and write to this folder location. We've gone into the preferences in iTunes itself and told it where we want it to find the iTunes Media folder. We also tried moving the iTunes media folder into the public shared music folder, and that didn't do a darn thing either. Nothing works.
    I feel like we are missing some critical step somewhere. Or maybe we screwed something up somehow. I don't know. All I know is that it seems crazy if we're not going to be able to access the exact same version of iTunes complete with playlists. What gives?
    Please help! Thank you!

    We've gone into the preferences in iTunes itself and told it where we want it to find the iTunes Media folder.
    This step is wrong. Make sure the iTunes folder in your profile is visible from his login, then press and hold down shift as you launch iTunes and browse to the iTunes Library.itl file in your library. It may be easier to store the library at C:\iTunes and have both accounts access it there.
    See Backup your iTunes for Windows library with SyncToy for advice on how to keep the backup copy of your library on the external drive up to date.
    tt2

  • How-to access username and password protected Java EE Web services from ADF

    The title of this post is exactly the same as this article by Frank Nimphius:
    http://www.oracle.com/technology/products/jdev/howtos/1013/protectedws/access_protected_web_services_from_adf.htm
    The article addresses the problem of securing web services using usernames and passwords, when those web services are accessed through a proxy or a data control. In the examples, the user names and passwords are specified, whether in the code or the definition of data controls. (SKING/SKING).
    In a very common scenario, users login to reach a page, for example, A.jspx, which contains a button that calls a web service, for example displayDate. Suppose that user has logged in by username/pass of (AHUNOLD/AHUNOLD) and AHUNOLD has access to the service and the page. Is there any way to pass the logged in user name and password to the webservice ? Of course we can hard-code the username in the data control definition or proxy code, but this is just one of the thousands of users who have access to the service and the authentication is not dynamic this way.
    Hope my question is clear. Wishing you all a great Christmas.
    Farbod

    Hi Frank, and happy new year.
    Are you implying that it couldn't be done declaratively? What is your suggestion for this problem? You know the problem... As I described:
    - I need to secure my web services, so when exposed, no one from inside network or the internet, can access the web service without proper permission
    - The web services are shown as web controls on jspx pages. The user has logged in before reaching the page. It is irrelevant to ask him to enter user name and password again.
    - I have user names, passwords and roles in Oracle Internet Directory (Identity Management). It provides some APIs and I can retrieve the usernames and attempt logging in programmically. But how can I get username and password from the session in ADF application?
    I guess using SAML or certificate could be the solution, but I have a problem with SAML, described here:
    Re: Webservices Security, SAML, and Identity Management (OID)
    Best Regards,
    Farbod

  • How to Access Word and Excel on my ipad

    I am going to Europe this month and I do NOT want to bring my PC. I need to have access to my Microsoft Word and Excel files. I will need to crete, edot and email these files.  I have heard that I need something called CloudOn and DropBox.  Does Apple offer me the same capability using their Cloud?
    Any recommendations as to how to solve my problem?

    Stoofpilot wrote:
    Hi Allan, I understand that I can buy iWorks and get the applications.  Any idea as to how I can upload my files from my PC to the iCloud?
    Open your web browser on your PC (I recommend fireFox or Chrome rather that IE for this) to www.icloud.com. Login and then selct iwork. Click on teh appropriate app on the tup menu, then the Gear icon to the right and select upload document.
    Open the iworks app you selected (Pages for example) and select the document. You will be prompted to make a copy or convert.
    If you use Dropbox, you will have the option to open a document in any app on iPad compatbile with its file format, including Pages, Numbers, etc. or Cloud on or other alternative app.

  • How to access survey and poll portal?

    hi,
    i got through the document and that say, this is the out of box facility. how can i make a portal link, by clicking that i can access the survey and poll facility?
    please give me steps?
    dhananjay

    You have to add the "Sruvey builder" portlet to an existing page to allow for creation of survey's polls. During creation, you can choose a page to publish the survey to.
    Otherwise, you can create a page and add the Survey FORM portlet to it. Then edit the portlet to display your created survey/poll.
    See the portal admin guide for additional info.

Maybe you are looking for