Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

datetime und SQL Server 2000

Empfohlene Antworten

Veröffentlicht

Gibt es beim SQL Server 2000 eine Möglichkeit eine Spalte wie datetime ohne programmieren so einstellen das die sich immer beim update auf aktuelle datum setzt

Beispiel : zwei spalte erst ist name zweite letzteaenderung in der spalte name steht test in letzteaenderung steht 8.12.2003 11:02 ....

Jetzt mache ich update set name = test1 where name = test

und letzteaenderung ändert sich automatisch auf aktuelle datum.

Ich habe mit timestamp probiert aber dann muß ich immer converten und das gefehlt mir nicht

Du kannst einen Trigger für die Tabelle erstellen. Der reagiert dann immer beim Update bzw. Insert der Tabelle und setzt das Datum entsprechend. Das könnte dann z.B. so aussehen:


CREATE TRIGGER [CHANGE_DATE] ON [dbo].[TABELLE] 

FOR UPDATE,INSERT 


AS


UPDATE TABELLE SET DATUM = GETDATE() WHERE ID in (SELECT ID FROM INSERTED)


Da ersetzt du halt die Tabellen- und Feldnamen durch deine eigenen - wobei die Tabelle "INSERTED" eine temporäre Tabelle extra für die Trigger ist, in der alle geänderten und eingefügten Datensätze stehen - so würdest du halt für alle geänderten Sätze anhand der eindeutigen ID (oder wie du das auch immer realisierst) upgedatet!

Ein Problem ist dabei allerdings noch, daß der Trigger sich so rekursiv wieder aufrufen würde. Das müsste man noch entsprechend abfangen.

  • Autor

Vielen Dank für Antwort, ja mit dem Triger ist mir klar, ich dachte aber man kann es irgend wie automatisch einstellen wie zB timestap nur beim timestamp kriege ich es in Hex und nicht im Datatime ?!?

Ich schätze, du sitzt da einem landläufigen Irrtum auf.

Schlagen wir mal die Hilfe auf:

The Transact-SQL timestamp data type is not the same as the timestamp data type defined in the SQL-92 standard. The SQL-92 timestamp data type is equivalent to the Transact-SQL datetime data type.

A future release of Microsoft® SQL Server™ may modify the behavior of the Transact-SQL timestamp data type to align it with the behavior defined in the standard. At that time, the current timestamp data type will be replaced with a rowversion data type.

Microsoft® SQL Server™ 2000 introduces a rowversion synonym for the timestamp data type. Use rowversion instead of timestamp wherever possible in DDL statements. rowversion is subject to the behaviors of data type synonyms.

Alternativen:

Wenn du es also gemäß deinen Anforderungsparametern haben willst, wirst du, da gebe ich beetFreeQ völlig Recht, um einen Trigger wohl nicht herumkommen.

Wenn du allerdings keinen Wert auf das Datum legst, kannst du timestamp - oder besser rowversion - benutzen.

Vorschlag:

RTFM :rolleyes:

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.