DECLARE @MyTab1 TABLE
INSERT INTO @Mytab1 VALUES (newId(),’Ashish’)
SELECT * FROM @Mytab1
SELECT crdate AS CreatedDate,GetDate() As CurrentDate, Name from tempdb.dbo.sysobjects where name not like ‘sys%’
ORDER BY CrDate DESC
Execute the above query in any database multiple times with some seconds interval and you will see the CreatedDate and the CurrentDate very close to each other in the resultset. “CreatedDate” is the time when that table variable was created in the tempDB database and “CurrentDate” is the datetime when you executed the query. “CurrentDate” will always be greater (just milliseconds) than the “CreatedDate”. Each time you execute the query, It creates a random name prefixed with a # and there is no naming conflict and no error. A good article here.