Showing posts with label primarykey. Show all posts
Showing posts with label primarykey. Show all posts

Monday, March 26, 2012

PRIMARYKEY VIOLATION

Hi,
I am dealing with merge replication.
For identity columns EVEN seed value is set in Publisher database
and ODD seed value is set in Subscriber database(increment value 2) to avoid
insertion conflicts.
For a particular table, usually the records are inserted from
subscriber(through application) and rarely from publisher. During this change
an error 'Primary Violation' occurs.
(1) What is the reason for this?
(2) Is there any way to avoid this?
(3) How can I get the next identity value to be generated?
Thanks,
Soura
Its hard to say. Use the conflict viewer to see if you can figure out where
the two rows are coming from. Partitioning is the way to avoid this, but it
looks like you have done this.
A DBCC Checkident('tablename') will give you the current value, so add the
increment to it to get the next value.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"SouRa" <SouRa@.discussions.microsoft.com> wrote in message
news:4208FC88-5A06-46F8-BE66-64EFF7ECDBC4@.microsoft.com...
> Hi,
> I am dealing with merge replication.
> For identity columns EVEN seed value is set in Publisher database
> and ODD seed value is set in Subscriber database(increment value 2) to
> avoid
> insertion conflicts.
> For a particular table, usually the records are inserted from
> subscriber(through application) and rarely from publisher. During this
> change
> an error 'Primary Violation' occurs.
> (1) What is the reason for this?
> (2) Is there any way to avoid this?
> (3) How can I get the next identity value to be generated?
> Thanks,
> Soura
>
>
sql

Primarykey Fields

I'm try to get table columns name & primary key to generat Dlete/Insert
script to all my database tables..
I was able to get list of all user tables from sysobject and columns list
from syscolumns..
Now i need to know the primary key column (For delete Statments)..
How could i detrmine which column is primarykey or composite key'
thanxA couple of suggestions:
First, you may be trying to reinvent the wheel; have you looked at
using SQL-DMO or SCPTXFR to script out your database? May save you a
lot of time and energy.
Second, wherever possible, use the INFORMATION_SCHEMA views rather than
the system tables to query this type of information; look at the
following queries i nthe pubs database as an example:
SELECT *
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 'authors'
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE TABLE_NAME = 'authors'
Note that the identification of a primary key is a constraint on the
table, not a property of a column.
Of course, this only rings true for SQL Server 2000; no clue about
SS2005.
HTH,
Stu|||Islamegy (NULL_Islamegy_NULL@.yahoo.com) writes:
> I'm try to get table columns name & primary key to generat Dlete/Insert
> script to all my database tables..
> I was able to get list of all user tables from sysobject and columns list
> from syscolumns..
> Now i need to know the primary key column (For delete Statments)..
> How could i detrmine which column is primarykey or composite key'
> thanx
Here is a query that lists the PK columns for all tables in a database.
There is a restriction that the query as written will not cover keys
with more than 10 columns, but this is easy to address.
select o.name,
MAX(CASE ik.keyno WHEN 1 THEN c.name END) +
coalesce(MAX(CASE ik.keyno WHEN 2 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 3 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 4 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 5 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 6 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 7 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 8 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 9 THEN ', ' + c.name END), '') +
coalesce(MAX(CASE ik.keyno WHEN 10 THEN ', ' + c.name END), '')
from sysobjects o
join sysindexes i on i.id = o.id
join sysindexkeys ik on i.id = ik.id
and i.indid = ik.indid
join syscolumns c on ik.id = c.id
and ik.colid = c.colid
join sysobjects pk ON i.name = pk.name
AND o.id = pk.parent_obj
group by o.name
order by o.name
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanx so much for this query..
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns976FD9D836B2FYazorman@.127.0.0.1...
> Islamegy (NULL_Islamegy_NULL@.yahoo.com) writes:
> Here is a query that lists the PK columns for all tables in a database.
> There is a restriction that the query as written will not cover keys
> with more than 10 columns, but this is easy to address.
> select o.name,
> MAX(CASE ik.keyno WHEN 1 THEN c.name END) +
> coalesce(MAX(CASE ik.keyno WHEN 2 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 3 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 4 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 5 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 6 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 7 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 8 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 9 THEN ', ' + c.name END), '') +
> coalesce(MAX(CASE ik.keyno WHEN 10 THEN ', ' + c.name END), '')
> from sysobjects o
> join sysindexes i on i.id = o.id
> join sysindexkeys ik on i.id = ik.id
> and i.indid = ik.indid
> join syscolumns c on ik.id = c.id
> and ik.colid = c.colid
> join sysobjects pk ON i.name = pk.name
> AND o.id = pk.parent_obj
> group by o.name
> order by o.name
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx

PrimaryKey consisting of two PKs with autoincrement?

I want to create a table where I can make a history of a file, while it's
processed by my application. The file will change and even get a new file, so
I created a Document table and a Journal table. The Journal table contains
the time, the event that did occure and a FK to the Document table. One line
represents a specific document (one unique file).
I added two primary keys to this table, one for the transaction and one for
the document itself. So always when a file changes (gets a new file) a new
line will be inserted with a new document key, but the same transaction key.
When a completly new file gets processed a new transaction should start and
the document key will again begin by zero.
I just would like to new if it is possible to make the document key
autoincremental, so that I don't have to worry about it in the application. I
don't really think that the transaction key can be made autoincremental, as
the database does not know, if it is a completly new file or just a new
version of an older file.
But could there be any problems with making the document key
autoincremental? I just want it to be zero again, every time a new
transaction key starts, but I think the database will just count on.
Hi
Take a look at an INDETITY property that is a good choice for artificial
keys.
"Stampede" <Stampede@.discussions.microsoft.com> wrote in message
news:F835C787-5BC8-4835-A31D-D38C4EA581A1@.microsoft.com...
> I want to create a table where I can make a history of a file, while it's
> processed by my application. The file will change and even get a new file,
so
> I created a Document table and a Journal table. The Journal table contains
> the time, the event that did occure and a FK to the Document table. One
line
> represents a specific document (one unique file).
> I added two primary keys to this table, one for the transaction and one
for
> the document itself. So always when a file changes (gets a new file) a new
> line will be inserted with a new document key, but the same transaction
key.
> When a completly new file gets processed a new transaction should start
and
> the document key will again begin by zero.
> I just would like to new if it is possible to make the document key
> autoincremental, so that I don't have to worry about it in the
application. I
> don't really think that the transaction key can be made autoincremental,
as
> the database does not know, if it is a completly new file or just a new
> version of an older file.
> But could there be any problems with making the document key
> autoincremental? I just want it to be zero again, every time a new
> transaction key starts, but I think the database will just count on.

PrimaryKey consisting of two PKs with autoincrement?

I want to create a table where I can make a history of a file, while it's
processed by my application. The file will change and even get a new file, so
I created a Document table and a Journal table. The Journal table contains
the time, the event that did occure and a FK to the Document table. One line
represents a specific document (one unique file).
I added two primary keys to this table, one for the transaction and one for
the document itself. So always when a file changes (gets a new file) a new
line will be inserted with a new document key, but the same transaction key.
When a completly new file gets processed a new transaction should start and
the document key will again begin by zero.
I just would like to new if it is possible to make the document key
autoincremental, so that I don't have to worry about it in the application. I
don't really think that the transaction key can be made autoincremental, as
the database does not know, if it is a completly new file or just a new
version of an older file.
But could there be any problems with making the document key
autoincremental? I just want it to be zero again, every time a new
transaction key starts, but I think the database will just count on.Hi
Take a look at an INDETITY property that is a good choice for artificial
keys.
"Stampede" <Stampede@.discussions.microsoft.com> wrote in message
news:F835C787-5BC8-4835-A31D-D38C4EA581A1@.microsoft.com...
> I want to create a table where I can make a history of a file, while it's
> processed by my application. The file will change and even get a new file,
so
> I created a Document table and a Journal table. The Journal table contains
> the time, the event that did occure and a FK to the Document table. One
line
> represents a specific document (one unique file).
> I added two primary keys to this table, one for the transaction and one
for
> the document itself. So always when a file changes (gets a new file) a new
> line will be inserted with a new document key, but the same transaction
key.
> When a completly new file gets processed a new transaction should start
and
> the document key will again begin by zero.
> I just would like to new if it is possible to make the document key
> autoincremental, so that I don't have to worry about it in the
application. I
> don't really think that the transaction key can be made autoincremental,
as
> the database does not know, if it is a completly new file or just a new
> version of an older file.
> But could there be any problems with making the document key
> autoincremental? I just want it to be zero again, every time a new
> transaction key starts, but I think the database will just count on.

PrimaryKey consisting of two PKs with autoincrement?

I want to create a table where I can make a history of a file, while it's
processed by my application. The file will change and even get a new file, s
o
I created a Document table and a Journal table. The Journal table contains
the time, the event that did occure and a FK to the Document table. One line
represents a specific document (one unique file).
I added two primary keys to this table, one for the transaction and one for
the document itself. So always when a file changes (gets a new file) a new
line will be inserted with a new document key, but the same transaction key.
When a completly new file gets processed a new transaction should start and
the document key will again begin by zero.
I just would like to new if it is possible to make the document key
autoincremental, so that I don't have to worry about it in the application.
I
don't really think that the transaction key can be made autoincremental, as
the database does not know, if it is a completly new file or just a new
version of an older file.
But could there be any problems with making the document key
autoincremental? I just want it to be zero again, every time a new
transaction key starts, but I think the database will just count on.Hi
Take a look at an INDETITY property that is a good choice for artificial
keys.
"Stampede" <Stampede@.discussions.microsoft.com> wrote in message
news:F835C787-5BC8-4835-A31D-D38C4EA581A1@.microsoft.com...
> I want to create a table where I can make a history of a file, while it's
> processed by my application. The file will change and even get a new file,
so
> I created a Document table and a Journal table. The Journal table contains
> the time, the event that did occure and a FK to the Document table. One
line
> represents a specific document (one unique file).
> I added two primary keys to this table, one for the transaction and one
for
> the document itself. So always when a file changes (gets a new file) a new
> line will be inserted with a new document key, but the same transaction
key.
> When a completly new file gets processed a new transaction should start
and
> the document key will again begin by zero.
> I just would like to new if it is possible to make the document key
> autoincremental, so that I don't have to worry about it in the
application. I
> don't really think that the transaction key can be made autoincremental,
as
> the database does not know, if it is a completly new file or just a new
> version of an older file.
> But could there be any problems with making the document key
> autoincremental? I just want it to be zero again, every time a new
> transaction key starts, but I think the database will just count on.

PrimaryKey and unique

how can I design a table to get unique values in a column within the PK
columns?
Example:
Client (int, PK)
User (int, PK
Userid(char...)
userid's shoud be unique for a client. Other clients are allowed to have
same userid's as other clients. A second user of a client cannot have the
same userid as other user of this client.
thanks for any help.
Looks like you have it almost right:
alter table MyTable
add
constraint PK_MyTable primary key (ClientID, UserID)
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Michael Haberichter" <Haberichter@.community.nospam> wrote in message
news:ED15E772-0327-4C98-8FBD-92AE3717D1FB@.microsoft.com...
how can I design a table to get unique values in a column within the PK
columns?
Example:
Client (int, PK)
User (int, PK
Userid(char...)
userid's shoud be unique for a client. Other clients are allowed to have
same userid's as other clients. A second user of a client cannot have the
same userid as other user of this client.
thanks for any help.
sql

PrimaryKey and Index

All,
To my understanding, the primary key is automatically indexed.
But in Enterprise Mananger (Design table/ indexes keys). It shows:
(x) Create UNIQUE
O Constraint <-- this is select
O Index
and you can NOT change the selection.
So I am confused that if an index is created or not. Do I need to
create the (unique) index on the primary key column so I can search on
this column with best performance.
Thanks
John
Primary Keys are automatically indexed. you do not have to create the index
manually.
Note: This is NOT the case for Foreign Keys
Note2: By Default SQL Server will create Primary Keys as "Clustered"
indexes. You need to be careful as the Clustered index may be better placed
on another column or columns.
Cheers,
Greg Jackson
PDX, Oregon
|||A Primary Key is a Constraint, which is an element of your logical data
model, rather than an Index, which is a feature of your table's physical
implementation. Behind the scenes the result is the same - the PK constraint
is implemented as a unique index and you don't need to create another index
explicitly.
David Portas
SQL Server MVP
|||Thanks for the clarification from Greg and David.
How about the Unique Contraint? I think it is just like PK, isn't it?
|||In My mind, a unique constrain is mainly there for you alternate keys, where a primary key
constraint is there for your primary key.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Q. John Chen" <nonospam@.wowway.com> wrote in message
news:8488de58.0406170656.4e4dd32b@.posting.google.c om...
> Thanks for the clarification from Greg and David.
> How about the Unique Contraint? I think it is just like PK, isn't it?
|||A Unique Constraint is applied to force Non PKey Items Unique.
Pkey is defined for referential integrity purposes, etc.
Cheers
GAJ
|||Thank for your response.
My question is that whether an index will be automatically created for
a Unique constraint. So I don't have create index for the performance
reason.
Thanks again.
John.
"Jaxon" <GregoryAJackson@.hotmail.com> wrote in message news:<#$zxjzIVEHA.3656@.TK2MSFTNGP11.phx.gbl>...
> A Unique Constraint is applied to force Non PKey Items Unique.
> Pkey is defined for referential integrity purposes, etc.
>
> Cheers
>
> GAJ
|||On 21 Jun 2004 09:35:50 -0700, Q. John Chen wrote:

>Thank for your response.
>My question is that whether an index will be automatically created for
>a Unique constraint. So I don't have create index for the performance
>reason.
>Thanks again.
>John.
Hi John,
If you define a UNIQUE constraint, SQL Server will indeed create an index
that is used for enforcing the constraint, but can also be used to
optimize queries.
The index created will be nonclustered by default, but you can override
this if you prefer a clustered index - check BOL for details.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

PrimaryKey and Index

All,
To my understanding, the primary key is automatically indexed.
But in Enterprise Mananger (Design table/ indexes keys). It shows:
(x) Create UNIQUE
O Constraint <-- this is select
O Index
and you can NOT change the selection.
So I am confused that if an index is created or not. Do I need to
create the (unique) index on the primary key column so I can search on
this column with best performance.
Thanks
JohnPrimary Keys are automatically indexed. you do not have to create the index
manually.
Note: This is NOT the case for Foreign Keys
Note2: By Default SQL Server will create Primary Keys as "Clustered"
indexes. You need to be careful as the Clustered index may be better placed
on another column or columns.
Cheers,
Greg Jackson
PDX, Oregon|||A Primary Key is a Constraint, which is an element of your logical data
model, rather than an Index, which is a feature of your table's physical
implementation. Behind the scenes the result is the same - the PK constraint
is implemented as a unique index and you don't need to create another index
explicitly.
David Portas
SQL Server MVP
--|||Thanks for the clarification from Greg and David.
How about the Unique Contraint? I think it is just like PK, isn't it?|||In My mind, a unique constrain is mainly there for you alternate keys, where
a primary key
constraint is there for your primary key.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Q. John Chen" <nonospam@.wowway.com> wrote in message
news:8488de58.0406170656.4e4dd32b@.posting.google.com...
> Thanks for the clarification from Greg and David.
> How about the Unique Contraint? I think it is just like PK, isn't it?|||A Unique Constraint is applied to force Non PKey Items Unique.
Pkey is defined for referential integrity purposes, etc.
Cheers
GAJ|||Thank for your response.
My question is that whether an index will be automatically created for
a Unique constraint. So I don't have create index for the performance
reason.
Thanks again.
John.
"Jaxon" <GregoryAJackson@.hotmail.com> wrote in message news:<#$zxjzIVEHA.3656@.TK2MSFTNGP11.p
hx.gbl>...
> A Unique Constraint is applied to force Non PKey Items Unique.
> Pkey is defined for referential integrity purposes, etc.
>
> Cheers
>
> GAJ|||On 21 Jun 2004 09:35:50 -0700, Q. John Chen wrote:

>Thank for your response.
>My question is that whether an index will be automatically created for
>a Unique constraint. So I don't have create index for the performance
>reason.
>Thanks again.
>John.
Hi John,
If you define a UNIQUE constraint, SQL Server will indeed create an index
that is used for enforcing the constraint, but can also be used to
optimize queries.
The index created will be nonclustered by default, but you can override
this if you prefer a clustered index - check BOL for details.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

PrimaryKey and Index

All,
To my understanding, the primary key is automatically indexed.
But in Enterprise Mananger (Design table/ indexes keys). It shows:
(x) Create UNIQUE
O Constraint <-- this is select
O Index
and you can NOT change the selection.
So I am confused that if an index is created or not. Do I need to
create the (unique) index on the primary key column so I can search on
this column with best performance.
Thanks
JohnPrimary Keys are automatically indexed. you do not have to create the index
manually.
Note: This is NOT the case for Foreign Keys
Note2: By Default SQL Server will create Primary Keys as "Clustered"
indexes. You need to be careful as the Clustered index may be better placed
on another column or columns.
Cheers,
Greg Jackson
PDX, Oregon|||A Primary Key is a Constraint, which is an element of your logical data
model, rather than an Index, which is a feature of your table's physical
implementation. Behind the scenes the result is the same - the PK constraint
is implemented as a unique index and you don't need to create another index
explicitly.
--
David Portas
SQL Server MVP
--|||Thanks for the clarification from Greg and David.
How about the Unique Contraint? I think it is just like PK, isn't it?|||In My mind, a unique constrain is mainly there for you alternate keys, where a primary key
constraint is there for your primary key.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Q. John Chen" <nonospam@.wowway.com> wrote in message
news:8488de58.0406170656.4e4dd32b@.posting.google.com...
> Thanks for the clarification from Greg and David.
> How about the Unique Contraint? I think it is just like PK, isn't it?|||A Unique Constraint is applied to force Non PKey Items Unique.
Pkey is defined for referential integrity purposes, etc.
Cheers
GAJ|||Thank for your response.
My question is that whether an index will be automatically created for
a Unique constraint. So I don't have create index for the performance
reason.
Thanks again.
John.
"Jaxon" <GregoryAJackson@.hotmail.com> wrote in message news:<#$zxjzIVEHA.3656@.TK2MSFTNGP11.phx.gbl>...
> A Unique Constraint is applied to force Non PKey Items Unique.
> Pkey is defined for referential integrity purposes, etc.
>
> Cheers
>
> GAJ|||On 21 Jun 2004 09:35:50 -0700, Q. John Chen wrote:
>Thank for your response.
>My question is that whether an index will be automatically created for
>a Unique constraint. So I don't have create index for the performance
>reason.
>Thanks again.
>John.
Hi John,
If you define a UNIQUE constraint, SQL Server will indeed create an index
that is used for enforcing the constraint, but can also be used to
optimize queries.
The index created will be nonclustered by default, but you can override
this if you prefer a clustered index - check BOL for details.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 21, 2012

Primary Key Foreign Key Tables

Hi All,
i do have two table a Master and a Detail which has a primary
key on the Master Table and Foreign key on the Detail Table
How do i insist that when ever there is a entry in the Master table
there should atleast exist one record in the Detail Table. Any sort of
condition can be made
Thanks in advance
thomsonHave a look at BOL "Constraints" and "Foreign key constraints"
HTH
Gerard|||Circular references are complex in SQL. An easier way is to write a trigger
to check the existance of rows in the referencing table.
Anith|||This is typically handled best in a client application (e.g., an n-tier
object) as a business rule.
see the following link for some more thoughts on this:
http://expertanswercenter.techtarge...i976558,00.html
thomson wrote:

>Hi All,
> i do have two table a Master and a Detail which has a primary
>key on the Master Table and Foreign key on the Detail Table
>
>How do i insist that when ever there is a entry in the Master table
>there should atleast exist one record in the Detail Table. Any sort of
>condition can be made
>
>Thanks in advance
>thomson
>
>

Primary key details

I am looking for a query to get the PrimaryKey Name, primary key column
for a particular table.
The follwing query will give me the Key Name and the Table Name but not
the column Name. Can I get the column name also in this query.
select A.ID,A.Name as PrimaryKey, B.Name as MasterTable from sysobjects
A INNER JOIN sysobjects B
on A.Parent_obj= B.ID
where A.xType = 'PK'
Thanks in AdvanceWhat about
SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
HTH, Jens Suessmeyer.|||SQL novice
SELECT rc.constraint_name,
ccu_prim.TABLE_NAME AS prim_table,
ccu_prim.COLUMN_NAME AS prim_column,
ccu_for.TABLE_NAME AS for_table,
ccu_for.COLUMN_NAME AS for_column
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu_prim
INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
ON ccu_prim.CONSTRAINT_CATALOG = rc.UNIQUE_CONSTRAINT_CATALOG
AND ccu_prim.CONSTRAINT_SCHEMA = rc.UNIQUE_CONSTRAINT_SCHEMA
AND ccu_prim.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu_for
ON ccu_for.CONSTRAINT_CATALOG = rc.CONSTRAINT_CATALOG
AND ccu_for.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
AND ccu_for.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
ORDER BY rc.constraint_name, for_table, prim_column
"SQL novice" <balacr@.gmail.com> wrote in message
news:1132221814.286212.141430@.g14g2000cwa.googlegroups.com...
>I am looking for a query to get the PrimaryKey Name, primary key column
> for a particular table.
> The follwing query will give me the Key Name and the Table Name but not
> the column Name. Can I get the column name also in this query.
> select A.ID,A.Name as PrimaryKey, B.Name as MasterTable from sysobjects
> A INNER JOIN sysobjects B
> on A.Parent_obj= B.ID
> where A.xType = 'PK'
>
> Thanks in Advance
>|||you could use 'sp_help <nametable>' which will inform you about that.
"SQL novice" wrote:

> I am looking for a query to get the PrimaryKey Name, primary key column
> for a particular table.
> The follwing query will give me the Key Name and the Table Name but not
> the column Name. Can I get the column name also in this query.
> select A.ID,A.Name as PrimaryKey, B.Name as MasterTable from sysobjects
> A INNER JOIN sysobjects B
> on A.Parent_obj= B.ID
> where A.xType = 'PK'
>
> Thanks in Advance
>|||Thanks Jens and Uri,
This was very helpful.