Showing posts with label existance. Show all posts
Showing posts with label existance. Show all posts

Sunday, March 25, 2012

Check NT login existance

How do you check for the existance of an NT login (in the domain not on sql
server itself) in a script that uses sp_grantlogin?You can use SUSER_SID:
IF SUSER_SID('MyDomain\MyAccount') IS NULL
PRINT 'account does not exist'
ELSE
PRINT 'account exists'
Happy Holidays
Dan Guzman
SQL Server MVP
"Steve Morris" <SteveMorris@.discussions.microsoft.com> wrote in message
news:FB40D121-995B-42DE-B735-7597C4793404@.microsoft.com...
> How do you check for the existance of an NT login (in the domain not on
> sql
> server itself) in a script that uses sp_grantlogin?

Check NT login existance

How do you check for the existance of an NT login (in the domain not on sql
server itself) in a script that uses sp_grantlogin?
You can use SUSER_SID:
IF SUSER_SID('MyDomain\MyAccount') IS NULL
PRINT 'account does not exist'
ELSE
PRINT 'account exists'
Happy Holidays
Dan Guzman
SQL Server MVP
"Steve Morris" <SteveMorris@.discussions.microsoft.com> wrote in message
news:FB40D121-995B-42DE-B735-7597C4793404@.microsoft.com...
> How do you check for the existance of an NT login (in the domain not on
> sql
> server itself) in a script that uses sp_grantlogin?

Check NT login existance

How do you check for the existance of an NT login (in the domain not on sql
server itself) in a script that uses sp_grantlogin?You can use SUSER_SID:
IF SUSER_SID('MyDomain\MyAccount') IS NULL
PRINT 'account does not exist'
ELSE
PRINT 'account exists'
Happy Holidays
Dan Guzman
SQL Server MVP
"Steve Morris" <SteveMorris@.discussions.microsoft.com> wrote in message
news:FB40D121-995B-42DE-B735-7597C4793404@.microsoft.com...
> How do you check for the existance of an NT login (in the domain not on
> sql
> server itself) in a script that uses sp_grantlogin?sql

Thursday, March 22, 2012

Check If View Exists

I'm working on a project for my class. I have to test for the existance of a certain view, and if it exists I have to delete it before recreating it. I figure it involves an IF command, and I know how to create a view. Everything in between is a blank for me. Any help would be appreciated. Thanks in advance.

An easy way to do this is to use the INFORMATION SCHEMA objects. They provide a handy way to get at the tables/views/etc inside the database..

Code Snippet

USE MyDatabase;

SELECT * FROM INFORMATION_SCHEMA.VIEWS

If you need to look for anything else inside the database, there are a bunch of others:

http://msdn2.microsoft.com/en-us/library/ms186778.aspx

|||I really appreciate that. Thank you.

Check If View Exists

I'm working on a project for my class. I have to test for the existance of a certain view, and if it exists I have to delete it before recreating it. I figure it involves an IF command, and I know how to create a view. Everything in between is a blank for me. Any help would be appreciated. Thanks in advance.

An easy way to do this is to use the INFORMATION SCHEMA objects. They provide a handy way to get at the tables/views/etc inside the database..

Code Snippet

USE MyDatabase;

SELECT * FROM INFORMATION_SCHEMA.VIEWS

If you need to look for anything else inside the database, there are a bunch of others:

http://msdn2.microsoft.com/en-us/library/ms186778.aspx

|||I really appreciate that. Thank you.

Check If View Exists

I'm working on a project for my class. I have to test for the existance of a certain view, and if it exists I have to delete it before recreating it. I figure it involves an IF command, and I know how to create a view. Everything in between is a blank for me. Any help would be appreciated. Thanks in advance.

An easy way to do this is to use the INFORMATION SCHEMA objects. They provide a handy way to get at the tables/views/etc inside the database..

Code Snippet

USE MyDatabase;

SELECT * FROM INFORMATION_SCHEMA.VIEWS

If you need to look for anything else inside the database, there are a bunch of others:

http://msdn2.microsoft.com/en-us/library/ms186778.aspx

|||I really appreciate that. Thank you.