Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Primary Key Count

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 11 Sep 2007 20:12 GMT
I'm trying to export some data from one database and upload it to another and
I want to keep the routine generic.  My problems is that a couple of the
tables have two fields in the primary key.  How do I determine how many
fields in the key?  It seems like Table.PrimaryKey.Length has the information
I put in it, not information from the database...
Nicholas Paldino [.NET/C# MVP] - 11 Sep 2007 22:05 GMT
Jay,

   You will have to get this information from the database.  Of course,
this is database specific.  Which database are you using on each end?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> I'm trying to export some data from one database and upload it to another
> and
[quoted text clipped - 3 lines]
> information
> I put in it, not information from the database...
Jay - 12 Sep 2007 12:32 GMT
Nicholas,

It's a SQL 2005 database on both ends.

> Jay,
>
[quoted text clipped - 8 lines]
> > information
> > I put in it, not information from the database...
Nicholas Paldino [.NET/C# MVP] - 12 Sep 2007 15:42 GMT
Jay,

   In this case, you can just call the stored procedure sp_pkeys, passing
in the name of the table, and it will return a recordset with the columns
that make up the primary key for the table.

   If you want to get your hands dirty with the system views, then this is
the query you would run in SQL Server 2005:

select
sc.*
from
sys.indexes as si
 inner join sys.index_columns as sic on
  sic.object_id = si.object_id and
  sic.index_id = si.index_id
  inner join sys.columns as sc on
   sc.object_id = sic.object_id and
   sc.column_id = sic.column_id
where
si.is_primary_key <> 0 and
si.object_id = object_id('?')
order by
sic.key_ordinal

   Just replace ? with the name of the table in your database.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Nicholas,
>
[quoted text clipped - 14 lines]
>> > information
>> > I put in it, not information from the database...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.