Skip to content

Commit a4204d2

Browse files
committed
Add CURRENT_TIMESTAMP and DATETIMEFROMPARTS in not recommended
1 parent 6de4969 commit a4204d2

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

SQL Server Name Convention and T-SQL Programming Style.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,20 @@ More details about SQL Server data types and mapping it with another databases a
201201

202202
This is only recommendations! But it is consistent for choosing only 1 function from possibles alterntives and use only it.
203203

204-
| Not Recommended | Recommended | When and Why | More details |
205-
|-----------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------|----------------|
206-
| [`!=`][12] | [`<>`][12] | `<>` is [`ANSI`], `!=` not `ANSI`, [`<>` and `!=` are identical][13] | [13] |
207-
| [`CONVERT`][10] | [`CAST`][10] | `CAST` is [`ANSI`] | [14],[15] |
208-
| [`ISNULL`] | [`COALECSE`] | `COALECSE` is [`ANSI`] and supports more than two arguments, `ISNULL` has dangerous behaviour with possibility to implicit triming string | [16],[17] |
209-
| [`DATEDIFF`] | [`DATEADD`] | The predicate `MyDateTime < DATEADD(SECOND, -1, GETUTCDATE())` syntax is [`SARGable`] | [18],[19] |
210-
| [`SELECT`] | [`SET`] | Using `SET` (is [`ANSI`]) instead of `SELECT` when assigning variables due to properly work with `Msg 501 Subquery returned more than 1 value` | [20],[21],[22] |
211-
| [`STR`] | [`CAST`][10] | `STR` is not [`ANSI`], extremly slow, don't use more than 15 digits, and has rounding problem - use `CAST` plus concatenate instead `STR` | [23] |
212-
| [`ISNUMERIC`] | [`TRY_CONVERT`] | `ISNUMERIC` can often lead to data type conversion errors, when importing data. For SQL Server below 2012 use `WHERE` with `LIKE`. | [24] |
213-
| [`GETDATE`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
214-
| [`GETUTCDATE`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
215-
| [`SYSDATETIME`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
204+
| Not Recommended | Recommended | When and Why | More details |
205+
|-----------------------|-------------------- |------------------------------------------------------------------------------------------------------------------------------------------------|----------------|
206+
| [`!=`][12] | [`<>`][12] | `<>` is [`ANSI`], `!=` not `ANSI`, [`<>` and `!=` are identical][13] | [13] |
207+
| [`CONVERT`][10] | [`CAST`][10] | `CAST` is [`ANSI`] | [14],[15] |
208+
| [`ISNULL`] | [`COALECSE`] | `COALECSE` is [`ANSI`] and supports more than two arguments, `ISNULL` has dangerous behaviour with possibility to implicit triming string | [16],[17] |
209+
| [`DATEDIFF`] | [`DATEADD`] | The predicate `MyDateTime < DATEADD(SECOND, -1, GETUTCDATE())` syntax is [`SARGable`] | [18],[19] |
210+
| [`SELECT`] | [`SET`] | Using `SET` (is [`ANSI`]) instead of `SELECT` when assigning variables due to properly work with `Msg 501 Subquery returned more than 1 value` | [20],[21],[22] |
211+
| [`STR`] | [`CAST`][10] | `STR` is not [`ANSI`], extremly slow, don't use more than 15 digits, and has rounding problem - use `CAST` plus concatenate instead `STR` | [23] |
212+
| [`ISNUMERIC`] | [`TRY_CONVERT`] | `ISNUMERIC` can often lead to data type conversion errors, when importing data. For SQL Server below 2012 use `WHERE` with `LIKE`. | [24] |
213+
| [`GETDATE`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
214+
| [`GETUTCDATE`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
215+
| [`SYSDATETIME`] | [`SYSUTCDATETIME`] | Daylight Saving Time and other factors can play havoc with our dates and times, rounding to the nearest 3 milliseconds. | [25] |
216+
| [`CURRENT_TIMESTAMP`] | [`SYSUTCDATETIME`] | It's too similar to the poorly-named TIMESTAMP data type, which has nothing to do with dates and times and should be called ROWVERSION. | [26] |
217+
| [`DATETIMEFROMPARTS`] | [`DATETIME2FROMPARTS`] | It's too similar to the poorly-named TIMESTAMP data type, which has nothing to do with dates and times and should be called ROWVERSION. | [26] |
216218

217219
[12]:https://docs.microsoft.com/sql/t-sql/language-elements/comparison-operators-transact-sql
218220
[13]:https://dba.stackexchange.com/a/155670/107045
@@ -241,6 +243,8 @@ This is only recommendations! But it is consistent for choosing only 1 function
241243
[`GETDATE`]:https://docs.microsoft.com/sql/t-sql/functions/getdate-transact-sql
242244
[`GETUTCDATE`]:https://docs.microsoft.com/sql/t-sql/functions/getutcdate-transact-sql
243245
[`SYSDATETIME`]:https://docs.microsoft.com/sql/t-sql/functions/sysdatetime-transact-sql
246+
[26]:https://bornsql.ca/blog/dates-and-times-in-sql-server-more-functions-you-should-never-use/
247+
244248

245249
**[⬆ back to top](#table-of-contents)**
246250

0 commit comments

Comments
 (0)