Showing posts with label particular. Show all posts
Showing posts with label particular. Show all posts

Sunday, March 25, 2012

Determine if a column is indexed (and the index name)

Is there a slick way to determine if all the indexes (if any) for a particular field?

let's say:

tbPeople

ID (bigint)

FirstName (varchar(50))

LastName (varchar(50))

I need to determine if [FirstName] in indexed anywhere, and if so, what are the name(s) of the indexes.

thanks ahead of time.

Which version of SS are you using?

To select all indexes where the column is part of the key, in 2005, you can use:

select

object_name(si.[object_id])as table_name,

si.name as index_name,

index_col(object_name(sic.[object_id]), sic.index_id, sic.index_column_id)as column_name,

sic.key_ordinal,

sic.is_descending_key,

sic.is_included_column

from

sys.indexesas si

innerjoin

sys.index_columnsas sic

on si.[object_id] = sic.[object_id]

and si.index_id = sic.index_id

where

si.object_id=object_id('dbo.Employees')

andcolumnproperty(object_id('dbo.Employees'),'LastName','ColumnId')= sic.column_id

orderby

sic.[object_id],

sic.index_id

go

AMB

|||

Brilliant. Thanks. Was not aware of sys.index_columns.

Any cute tricks for the equivalent query on SS 2K?

|||

Try:

select

object_name(si.[id])as table_name,

si.name as index_name,

col_name(sic.[id], sic.colid)as column_name,

sic.keyno

from

sysindexesas si

innerjoin

sysindexkeysas sic

on si.[id] = sic.[id]

and si.indid = sic.indid

where

si.[id] =object_id('dbo.Employees')

andcol_name(sic.[id], sic.colid)='LastName'

orderby

sic.[id],

sic.indid

go

AMB

Thursday, March 22, 2012

Detecting status of snapshot agent...

Is there an easy way to determine the status/progress of the snapshot agent
for a particular merge publication?
Troy - much the same as the question for your merge agent:
sp_help_job will do it on an ad-hoc basis, but if you need to do something
as a result of the job status, you could modify this script to do it:
http://www.replicationanswers.com/Downloads/KillRunningJobs.txt
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .

Wednesday, March 21, 2012

Detecting Circular References.

Greetings All, this is my first time dealing with this particular issue
so I figured I would solicit your expertise :)
Annoted Version of DDL:
Create Table Company
(
ParentId int null,
PrimaryId int not null primary key,
CompanyName nvarchar(200) not null
)
Facts:
1.) PrimaryId is the PK of the Company.
2.) ParentId is the identifier of the Parent company if one exists.
3.) If ParentId is null then PrimaryId is its own parent.
4.) A company can have only one parent (hierarchcial graph).
5.) There is no one master company for all PrimaryId's. This is to say
you can have more than one hierarchy represented in the Company table:
A D
/ \ / \
B C E F
Where A and D are there own parents.
Problem:
I need to make sure that there can never be the case where a company is
simultaneously both the child and parent of another company, e.g.)
A is parent of B
B is parent of C
C is parent of D
D is parent of A <= Violation
Any help would be greatly appreciated.
TFDThis technique should work:
SET NOCOUNT ON
-- DROP TABLE Company
GO
Create Table Company
(
ParentId int null,
PrimaryId int not null primary key,
CompanyName nvarchar(200) --not null
)
GO
INSERT Company (ParentId, PrimaryId)
SELECT NULL, 1
UNION
SELECT 1, 2
UNION
SELECT 2, 3
UNION
SELECT 2, 4
UNION
SELECT 3, 5
UPDATE Company
SET ParentID = 5
WHERE PrimaryID = 1
GO
SELECT ParentId --Ancestor
, PrimaryId --Descendant
INTO #Hierarchy
FROM Company
WHERE ParentId IS NOT NULL
DECLARE @.BadHierarchy CHAR(1)
SET @.BadHierarchy = 'N'
WHILE 1 = 1 BEGIN
INSERT #Hierarchy
SELECT DISTINCT
p.ParentId
, c.PrimaryId
FROM #Hierarchy p
INNER JOIN #Hierarchy c
ON p.PrimaryId = c.ParentId
WHERE NOT EXISTS (SELECT * FROM #Hierarchy WHERE ParentID =
p.ParentID AND PrimaryId = c.PrimaryId)
IF EXISTS (SELECT * FROM #Hierarchy a WHERE EXISTS (SELECT * FROM
#Hierarchy b WHERE a.PrimaryID = b.ParentID AND a.ParentID =
b.PrimaryID)) BEGIN
SET @.BadHierarchy = 'Y'
BREAK
END
IF @.@.ROWCOUNT = 0 BREAK
END
SELECT @.BadHierarchy
SELECT * FROM #Hierarchy
DROP TABLE #Hierarchy|||I goofed on that one. That @.@.ROWCOUNT needs to be assigned to a
variable before the IF EXISTS statement above it, and that variable
needs to be checked where I'm checking @.@.ROWCOUNT.
-Alansql

Detecting a change in a particular field in a database

Is it possible, using VB code, to retain a user on a particular pageuntil the status of a certain field in a database is changed?
The scenario I am working on is that a person makes a reservation andhas to wait until that reservation has been accepted or rejected by theadministration.
Dim dsResv As DataSet
dsResv = objResv.DALgetResvStatus(resvId)
While (dsResv.Tables(0).Rows(0).Item("resvStatus") = "pending")
dsResv = objResv.DALgetResvStatus(resvId)
IfdsResv.Tables(0).Rows(0).Item("resvStatus") = "denied" Then
failure.Visible = True
LinkButton1.Visible = True
ElseIf dsResv.Tables(0).Rows(0).Item("resvStatus") = "reserved" Then
success.Visible = True
LinkButton1.Visible = True
End If
End While
This is how I tried to do it, but it doesnt seem to work.
Any suggestions?
If it is web application, use AJAX to send the request to the server and to get the response asynchronously without submitting the page to server.
For AJAX refer:
http://aspalliance.com/716|||Any other way??
i mean without javascripting

Detect Existing Subscription on Subscriber

Hi all,
Is there a way to check the subscriber if a particular subscription exists
using SQLDMO ActiveX control? If not, how would it be done through stored
procedure?
Thanks,
Tom
Tom,
on the subscriber you could run sp_helppullsubscription or just query the
MSreplication_subscriptions table - I think this is the easiest method.
Using SQLDMO there is a TransPullSubscriptions collection that could be
iterated, although I'm not too sure if this works on the subscriber.
HTH,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)