Showing posts with label foreign. Show all posts
Showing posts with label foreign. Show all posts

Tuesday, March 20, 2012

Query to only display information from one table where the foreign key doesnt exist in the

I want to make a query, stored procedure, or whatever which will only display the primary key where there does no exist a foreign key in linked table.

For example. If I had two tables with a one to many relationship.

A [Computer] has one or more [Hard Drives].

I want to select only those computers which do not have a Hard Drive(s) associated with them. That is, show all computers where the Computer_ID field in the [Hard Drives] table does not exist.

This seems simple but I'm drawing a blank here.

SELECT * FROM Computer where ComputerId NOT IN (SELECT ComputerId FROM [Hard Drives])

Monday, February 20, 2012

Query System Tables for FK/Not For Replication

I'm trying to ensure that none of the 47 foreign keys in my database are
being enforced for replication. Is this information stored in a system
table?
MichelleCheck the CnstIsNotRepl property using OBJECTPROPERTY function.
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"michelle" <michelle@.nospam.com> wrote in message
news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
> I'm trying to ensure that none of the 47 foreign keys in my database are
> being enforced for replication. Is this information stored in a system
> table?
> Michelle
>|||Thanks!
SELECT * FROM dbo.sysobjects
WHERE
OBJECTPROPERTY(id, N'CnstIsNotRepl') = 0
AND xtype = 'FK'
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:%231CxJMsuEHA.4008@.TK2MSFTNGP10.phx.gbl...
> Check the CnstIsNotRepl property using OBJECTPROPERTY function.
> --
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "michelle" <michelle@.nospam.com> wrote in message
> news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
> > I'm trying to ensure that none of the 47 foreign keys in my database are
> > being enforced for replication. Is this information stored in a system
> > table?
> >
> > Michelle
> >
> >
>

Query System Tables for FK/Not For Replication

I'm trying to ensure that none of the 47 foreign keys in my database are
being enforced for replication. Is this information stored in a system
table?
MichelleCheck the CnstIsNotRepl property using OBJECTPROPERTY function.
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"michelle" <michelle@.nospam.com> wrote in message
news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
> I'm trying to ensure that none of the 47 foreign keys in my database are
> being enforced for replication. Is this information stored in a system
> table?
> Michelle
>|||Thanks!
SELECT * FROM dbo.sysobjects
WHERE
OBJECTPROPERTY(id, N'CnstIsNotRepl') = 0
AND xtype = 'FK'
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:%231CxJMsuEHA.4008@.TK2MSFTNGP10.phx.gbl...
> Check the CnstIsNotRepl property using OBJECTPROPERTY function.
> --
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "michelle" <michelle@.nospam.com> wrote in message
> news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
>

Query System Tables for FK/Not For Replication

I'm trying to ensure that none of the 47 foreign keys in my database are
being enforced for replication. Is this information stored in a system
table?
Michelle
Check the CnstIsNotRepl property using OBJECTPROPERTY function.
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"michelle" <michelle@.nospam.com> wrote in message
news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
> I'm trying to ensure that none of the 47 foreign keys in my database are
> being enforced for replication. Is this information stored in a system
> table?
> Michelle
>
|||Thanks!
SELECT * FROM dbo.sysobjects
WHERE
OBJECTPROPERTY(id, N'CnstIsNotRepl') = 0
AND xtype = 'FK'
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:%231CxJMsuEHA.4008@.TK2MSFTNGP10.phx.gbl...
> Check the CnstIsNotRepl property using OBJECTPROPERTY function.
> --
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "michelle" <michelle@.nospam.com> wrote in message
> news:e33lCGsuEHA.1420@.TK2MSFTNGP10.phx.gbl...
>