Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored procedure to return user tables in database?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00638154
Message ID:
00638806
Vues:
16
Thanks for the info Dave.

Al


>>I had a look in the master database and there are 930 stored procedures! Does anyone know if there is a sp in the master database that will return the names of the user tables when passed the database name? In the meantime, I'll try to figure it out myself...
>>
>>Thanks in advance,
>>
>>Al
>
>The .NET OleDbConnection class has a method called GetOleDbSchemaTable that returns table names in a database.
>
>using System;
>using System.Data;
>using System.Data.OleDb;
>
>namespace ConsoleApplication2
>{
>	/// <summary>
>	/// Summary description for Class1.
>	/// </summary>
>	class Class1
>	{
>		/// <summary>
>		/// The main entry point for the application.
>		/// </summary>
>		[STAThread]
>		static void Main(string[] args)
>		{
>			String myConnectionString;
>			myConnectionString = "Provider=SQLOLEDB;Data Source=YOURSQLNAMEHERE;Initial Catalog=Northwind;" +
>				"User Id=sa;password=;";
>			OleDbConnection myConnection = new OleDbConnection(myConnectionString);
>
>//			DataTable dt = GetTables(myConnection);
>
>			myConnection.Open();
>			DataTable dt = myConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
>				new object[] {null, null, null, "TABLE"});
>			myConnection.Close();
>
>			int i;
>
>				foreach(DataRow myRow in dt.Rows)
>				{
>//					foreach(DataColumn myCol in dt.Columns)
>//					{
>						Console.WriteLine(myRow[2]);
>//					}
>				}
>			Console.ReadLine();
>
>		}
>
>	}
>}
>
>
>
>When I look at SQL Profiler, it shows that the following sp was executed from the above code:
>
>exec [Northwind]..sp_tables_rowset NULL,N'TABLE'
>
>I don't know how OleDb translates it, but the following sp workes in QA
>
>EXEC sp_tables null, null, null, "'TABLE'"
>
>Using SQL2000, of course.
Al Williams

Anola MB, CANADA
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform