Re: Primary Key Count



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...





.



Relevant Pages

  • Re: Stored procs and DB-aware components possible at all?
    ... a primary key but it just wouldn't work. ... Performance became dreadfully slow if the database ... documented in BOL, BTW). ... So I had to give up on INNER JOIN. ...
    (borland.public.delphi.database.ado)
  • Re: problem using identity column as primary key
    ... >> I am thinking of creating an identity column to use it as primary key ... More and more programmers who have absolutely no database training are ... the gap in the sequence is not filled in and the sequence ... vin CHARNOT NULL REFERENCES Motorpool); ...
    (microsoft.public.sqlserver.programming)
  • Re: Data access perfomance
    ... Hi, thanks I kind reduce the time inserting into the database, the problem ... was that I had a primary key on the table, ... >> I can't discuss Oracle, but for SQL Server, the following measures ...
    (microsoft.public.data.oledb)
  • Re: Data generator help!!
    ... in c# to populate the database (sql server 2005), ... the database, then get the data type of the coulumn, if the data type ... FROM sysobjects SO JOIN syscolumns SC ON SO.id = SC.id INNER JOIN ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Updating the SQL key value
    ... before creating the database, by the time I've come to pick a primary key, ... articles, each of which must be issued under a particular licence (e.g. ... GPL GNU General Public Licence http://www.gnu ... ...
    (comp.lang.php)