Showing posts with label various. Show all posts
Showing posts with label various. Show all posts

Tuesday, March 6, 2012

accuracy vs generalization

Hi!

So sorry for posting yet another one of my silly posts about the correct way of doing things!

I am using Stored Procedures to do various things in my database (inserting/deleting/updating) and using SQL Server 2000 SP4

The current situation is that I have a stored procedure which checks certain user details and returns either -1 or 1 as a success indicator to the caller.

Now, obviously if we executed several queries in this stored procedure, performance will be an issue.

However, I have no idea how to balance up the whole "more useful information" vs "general information". What I mean is this:

if we are checking 3 items in a table, I want to return the success value back to the caller - in this case, we could do an IF statement to see if the record exists, if it does, set the return value to 1, else, -1.

But then you may want to be more informative to the user, specifically stating what part of the information they entered is incorrect/invalid. So having this in mind, we would then need to execute, say, 3 queries to return a more specific "error" value.

What should I do in this case?

I want to check the username, password and if the account is activated.

Currently I have this query going on:

IF EXISTS (SELECT [ID] FROM Users WHERE username = @.un AND [password] = @.pw AND activate = 1)

SET @.theResult = 1

ELSE

SET @.theResult = -1

firstly, is that the good way of doing things? if not - then what is the better way?

secondly, if we decide that we want a specific detailed return value/error message, it would mean I have to check the results I want using a couple more queries, such as one query to check username, one query to check password and another to check if the account is active or not and then return the appropriate value back to the caller.

is this a good way of doing things? I am confused and stuck!

Many thanks for your valuable response :)

>>Now, obviously if we executed several queries in this stored procedure, performance will be an issue.<<

This isn't necessarily true, but it is always better to minimize the number of queries.

Take this query:

IF EXISTS (SELECT [ID] FROM Users WHERE username = @.un AND [password] = @.pw AND activate = 1)

SET @.theResult = 1

ELSE

SET @.theResult = -1

A better way to write this might be:

select ID, case when activate = 0 then 'inactive' else 'active' end as activeStatus,
case when password = @.pw then 'correct' else 'incorrect' end as pwCheck
from users
where username = @.un

Then, the caller can interpret the details as they see fit:

No result set - invalid user name, the other two possibilities are obvious.

|||Many thanks!

Sunday, February 19, 2012

Accessing System Views via linked servers

Is there anyway to access system views on/from a linked server?
I have unsuccessfully tried various permutations of
select *
from [MDEDATAWTD\ss2005].master.[information_schema.colums]
ThanksYou are making the table and column name appear as one object. This works fine for me:


SELECT *
FROM [MyServer].master.information_schema.columns
2005 also. High priveledge linked account.

HTH|||You are making the table and column name appear as one object.Not very helpful huh?

I mean with this:

...[information_schema.colums]|||Thanks.

It is not working for me even though I can access the data bases directly. I am going to try a different tack. This approach is chewing too much time.|||Ok - but if you do decide to stick with it check that your linked server maps to an account with the correct privledges. Remember - your domain account could be locally mapped to a remote SQL account that has insufficient rights.

I suppose we'd need to know the error too.

Anyway - just a thought :)|||Thanks for the additional insight.

I also discovered that I really didn't want the system tables from a "linked server" but the system views from a database on the "linked server". Either way I could not get it to work. As I said the benefit gained by procedurally scripting the change looks to be longer than just manually doing the change.

FYI: The error was of the "object does not exist" variety.|||Awww, c'mon Bartron...don't give up now! :) You'll need the linked server experience somewhere down the line!

It's very common for the "object does not exist" error to be due to permissions issues as previously pointed out.