Creating a time table in SQL Server

preview_player
Показать описание
In this video, we'll create a time table, with a row every 10 minutes or 20 seconds, and add columns for hour, minute and second.
My SQL Server Udemy courses are:
----
Time tables allow to you pre-calculate times and their properties, such as hour, minute and second. This way, you don't have to work them out multiple times, and you can index them to speed up your queries.

The code in this video is as follows:

DROP TABLE IF EXISTS tblTime;

CREATE TABLE tblTime
(myTime time,
myHour tinyint,
myMinute tinyint,
mySecond tinyint)

INSERT INTO tblTime(myTime)
SELECT DISTINCT CONVERT(TIME,
DATEADD(SECOND, 20 * ROW_NUMBER() OVER(ORDER BY (SELECT NULL)), '2029-12-31 00:00:00'))

UPDATE tblTime
SET myHour = DATEPART(HOUR, myTime),
myMinute = DATEPART(MINUTE, myTime),
mySecond = DATEPART(SECOND, myTime)

SELECT * FROM tblTime
ORDER BY myTime
----
Links to my website are:
Рекомендации по теме
Комментарии
Автор

Hello if you allow me a joke- have you check the transaction log file after this insert?
Thank you for another useful video

florincopaci