The T-SQL (Transact SQL) language is an extension of the standard SQL query language. It includes tools that allow users to control access to the different type of data in Microsoft SQL databases. Each database has a counter that is incremented for each insert or update operation performed on the database tables. The timestamp data type displays automatically generated unique binary numbers to stamp a version of table rows within your database. You need to define timestamp variable in the database table to convert a timestamp to decimal in T-SQL.
- Skill level:
- Moderately Easy
Click the "Start" button in Windows and select "Microsoft SQL" from the "All Programs" menu to open the SQL management console.
Type in the following code in the console window:
CREATE TABLE MyTest2 (my Key int PRIMARY KEY
,my Value int, TS timestamp);
INSERT INTO MyTest2 (my Key, my Value) VALUES (1, 0);
INSERT INTO MyTest2 (my Key, my Value) VALUES (2, 0);
DECLARE @t TABLE (my Key int);
SET my Value = 2
OUTPUT inserted.myKey INTO @t(myKey)
WHERE my Key = 1
AND TS = my Value;
IF (SELECT COUNT(*) FROM @t) = 0
BEGIN RAISERROR ('error changing row with my Key = %d') END;
This creates the "myTest2" database and indexes it with the "myKey" primary key using the "TS" variable in your SELECT query.
Click "File" and "Run" to run the T-SQL query for the conversion of the timestamp counter in the "myTest2" database to the decimal data type.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for