Here is the most random way I can think of:
Select NewID() as UserName, NewID() as Password
Of course, your users aren't going to like this because it is really very long:
UserName Password
------------------------------------ ------------------------------------
F050EF1A-1D6C-4A20-991C-F6B034AEBD2E 86C8D5FC-D09E-45FF-9A4F-041239082C5E
So let's shorten it to 8 characters:
Select
SubString (Cast (NewID() as VarChar(50)), 1, 8) as UserName,
SubString (Cast (NewID() as VarChar(50)), 1, 8) as Password
This looks better:
UserName Password
-------- --------
63B1A547 D5566B8C
Since you want this to be generated when the row is saved, you probably have an INSERT statement that puts the account owner's information into the database. Modify that particular line of code to do this insert as well:
Insert Into AccountTable (UserName, Password)
Select
SubString (Cast (NewID() as VarChar(50)), 1, 8) as UserName,
SubString (Cast (NewID() as VarChar(50)), 1, 8) as Password
Of course.. since you know the account owners name, you can query back to get the owner. A much better idea is to have an identity column on the table, and use Scope_Identity
to get the row you just inserted.