Hello All,
I have a problem as follows
if i execute SELECT GETDATE() statement multiple times in a single run it returns me the same datetime without any difference in even milliseconds.
I am unable to figure out what is wrong. I am assuming that whenever executed in a transaction it will give the same result.
could anybody let me know what is correct. Thanks for your help in advance.
SELECT GETDATE()
SELECT GETDATE()
SELECT GETDATE()
SELECT GETDATE()
SELECT GETDATE()
SELECT GETDATE()
SELECT GETDATE()
even then i get the same date.
What are you trying to achieve? The amount of time it takes to run multiple Select GetDate() is very minor. We would be able to help you better if we knew what your goal was.
|||Hi, mate
I just executed:
SELECTGETDATE()SELECT *FROM Table1SELECTGETDATE()
and the the two dates was different. (Table1 has 120 000 rows)
This means that the query is executing too fast (in less than a millisecond) and that is why you receive the same results.
||| yeah... if u execute query select getdate() several times one after another u cant understand the difference of milliseconds. don't worry...
Hi Diamsorn,
Thanks for the reply. but all i am trying to do was i have a history table and i have included modified date as a part of primary key and when i am trying to update my main table i am inserting a record into history table. eventhough i am doing it in different time system says it is a violation of primary key.
For eg. Table1 is having below columns
Column1 Column2 Column3 and Suppose Primary key is composite key of column1 and column2
I have HistoryTable having columns
Column1 Column2 modifieddate and Suppose Primary key is composite key of Column1,Column2 and Modifieddate. but when i am trying to update the table1, and though trigger i am capturing getdate() to fill modifieddate, then as it is not different it is giving error.
how to overcome this problem?
Gneralproblem
|||Which table is giving the primary key violation error? Table1 or HistoryTable.
What is your purpose of having a composite primary key in your history table of column1, column2, and modified date?
I would move away from using a trigger to insert into your history table, and do your update/insert inside of a transaction in a stored procedure. Triggers are a maintenance nightmare and I avoid them personally at all costs.
|||Hi Diamsorn,
History table is giving me error. As i have to update the same record in Table1 and track the changes in HistoryTable. As my operation is so fast and as it is caputring same date it is giving primary key violation.
I would appreciate if any way to handle this problem using Triggers.
Thanks,
GeneralProblem
No comments:
Post a Comment