Change sql server user account password

As most of us know or read that we must have to change  password frequantly to enhance security. so some time we need to do it useing sql queries espisal when we can have gui interface for do such operation so there is a bild in stored procedure that allow us to such thing in easy way:

 

syntax:

 

sp_password [ [ @old = ] ‘old_password’ , ]   { [ @new =] ‘new_password’ }     [ , [ @loginame = ] ‘login’ 

 

usage:

to change current active account we us it like this example:

 

sp_password ‘currentPSWD’, ‘newPSWD’ 

 

and in case we want to change for another user account we do that by adding user login by end of query ex.:

 

sp_password ‘currentPSWD’, ‘newPSWD’ , ‘userName’

 

 

:)

how to find missing value in a sequence

most of the time when someone design a database table and use the uinquie identifire to be not automatic submited and be sequential number they face some problems with when data record deleted which cause gaps between numbers and with big sarrow non of exisiting DBMs  (until I wrote this entry) contain magic function that could fill ids with missing numbers so I searched the internet and scratched my head until I found the amazing solution to get the missing number and to use them to reassign them to new record by using exclusion join as in following example (I use SQL Server)

 

Step 1: create data table

Create table sequance (id int not null primary key unique);

 

Step 2 : Insert values

Insert into sequance values (1);
Go
Insert into sequance values (2);
Go
Insert into sequance values (3);
Go
Insert into sequance values (4);
Go
Insert into sequance values (5);
Go
Insert into sequance values (7);
Go
Insert into sequance values (10);
Go
Insert into sequance values (11);
Go
Insert into sequance values (20);
Go

 

Step 3: find where gap start

 

 select start = s1.id + 1

  from sequance as s1 left outer join sequance as s2 on s1.id + 1 = s2.id

where s2.id is null

 

what exactly  we did here we join our table with it self on the id value + 1 so each value from first source joined with next sequence if exist from next source then if the sequence break the 2ed part value will be null.

and by taking where 2ed source value is null we take sequences  break start point

 

so to use this gap values we just take minimum value from returned value and assign it as new id for new inserted row.

 

enjoy your time thinking ;)