Friday, January 21, 2011

Table Variable-The Updating

This script will show the creation of a "Table Variable", the inserting of three records into that table, and then the changing of one record. The end of the script shows all the records currently in the table, with the changed  record.

  DECLARE @varTable table(    
  Id int IDENTITY(1,1),    
  UserName VARCHAR(25),    
  Passwd VARCHAR(15)    
  )    
   
  INSERT into @varTable(UserName,Passwd)    
  Values('Jib','JibsPasswd')    
   
  INSERT into @varTable(UserName,Passwd)    
  Values('Jax','JaxsPasswd')   
    
  INSERT into @varTable(UserName,Passwd)    
  Values('Who','WhosPasswd')   
    
  SELECT *  
  From @varTable  
    
  UPDATE @varTable  
  Set Passwd='awesome'  
  Where UserName='Jib'  
    
  SELECT *  
  From @varTable  
    
  GO    
    

More to Come, CA.

No comments:

Post a Comment