Re: Primary Key Count
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 12 Sep 2007 10:42:11 -0400
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Jay" <Jay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CDB1B0DE-E813-4545-8749-A90F5293EE31@xxxxxxxxxxxxxxxx
Nicholas,
It's a SQL 2005 database on both ends.
"Nicholas Paldino [.NET/C# MVP]" wrote:
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?
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Jay" <Jay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:99EEA2BA-CEFF-41A0-BC04-6B8FA4A2A810@xxxxxxxxxxxxxxxx
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...
.
- References:
- Re: Primary Key Count
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Primary Key Count
- Prev by Date: Re: Blitting
- Next by Date: Re: High Performance Access to a Static Object's List<string>
- Previous by thread: Re: Primary Key Count
- Next by thread: Regular Expression Issue
- Index(es):
Relevant Pages
|