简体   繁体   English

在 SQL Server 中存储歌曲的持续时间

[英]Store duration of song in SQL Server

I'm going to store the Length of songs in my table and I chose the data type as decimal(2,2), but I got error.我要将歌曲长度存储在我的表中,并且我选择了数据类型为十进制(2,2),但我得到了错误。 I search for this question alot but couldnt solve it.我经常搜索这个问题,但无法解决。 Can any one tell me that which data type should I use and how exactly must write it in query?谁能告诉我应该使用哪种数据类型以及如何在查询中准确地编写它?

在此处输入图像描述

I'm not sure decimal is the right way to store time, as the info after the decimal point isn't 100 based.我不确定十进制是存储时间的正确方法,因为小数点后的信息不是基于 100。

Could you store the duration as an integer?您可以将持续时间存储为整数吗? In seconds?片刻之间?

Writing: 3m:30s -> 3*60+30 = 210 seconds写作:3m:30s -> 3*60+30 = 210 秒

Reading: 210 seconds/60 + seconds%60 (3 + 30)读数: 210 seconds/60 + seconds%60 (3 + 30)

Your decimal specification is incorrect.您的十进制规范不正确。 decimal(2,2) says you have 2 numbers, 2 of which come after the decimal. decimal(2,2)表示您有 2 个数字,其中 2 个在小数点后。 Try decimal(3,2) and that should fix your error, but you might need to play with the precision and scale as you work further.尝试decimal(3,2) ,这应该可以解决您的错误,但您可能需要在进一步工作时使用精度和比例。

More information: https://docs.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql更多信息: https ://docs.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql

decimal[ (p[ ,s] )] and numeric[ (p[ ,s] )] decimal[ (p[ ,s] )]numeric[ (p[ ,s] )]

p (precision) The maximum total number of decimal digits to be stored. p(精度)要存储的十进制数字的最大总数。 This number includes both the left and the right sides of the decimal point.这个数字包括小数点的左边和右边。 The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.精度必须是 1 到最大精度 38 之间的值。默认精度为 18。

s (scale) The number of decimal digits that are stored to the right of the decimal point. s(刻度)存储在小数点右侧的小数位数。 This number is subtracted from p to determine the maximum number of digits to the left of the decimal point.从 p 中减去该数字以确定小数点左侧的最大位数。 Scale must be a value from 0 through p, and can only be specified if precision is specified. Scale 必须是从 0 到 p 的值,并且只能在指定精度的情况下指定。 The default scale is 0 and so 0 <= s <= p.默认比例为 0,因此 0 <= s <= p。 Maximum storage sizes vary, based on the precision.最大存储大小因精度而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM