Skip to content

Commit 084252c

Browse files
authored
Add warning about varchar(max) (#688)
* Add warning about varchar(max) * Fix copy/paste issue * Implement Claude's suggestions. * Updated comment. Also fixed example statements
1 parent c3b9421 commit 084252c

File tree

1 file changed

+12
-8
lines changed
  • docs/contributing/code-style

1 file changed

+12
-8
lines changed

docs/contributing/code-style/sql.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,8 @@ WHERE
462462
[Column] IS NULL
463463
GO
464464

465-
ALTER TABLE
466-
[dbo].[Column]
467-
ALTER COLUMN
468-
[Column] INT NOT NULL
465+
ALTER TABLE [dbo].[Table]
466+
ALTER COLUMN [Column] INT NOT NULL
469467
GO
470468
```
471469

@@ -474,14 +472,20 @@ This is better:
474472
```sql
475473
IF COL_LENGTH('[dbo].[Table]', 'Column' IS NULL
476474
BEGIN
477-
ALTER TABLE
478-
[dbo].[Column]
479-
ADD
480-
[Column] INT NOT NULL CONSTRAINT DF_Table_Column DEFAULT 0
475+
ALTER TABLE [dbo].[Table]
476+
ADD [Column] INT NOT NULL CONSTRAINT DF_Table_Column DEFAULT 0
481477
END
482478
GO
483479
```
484480

481+
:::warning Do not use defaults for string columns
482+
483+
Default values should only be used for integral types (`BIT`, `TINYINT`, `SMALLINT`, `INT`,
484+
`BIGINT`). Do not provide default values for string columns (`VARCHAR`, `NVARCHAR`, or their `MAX`
485+
variants), as this can lead to unnecessary storage overhead and performance issues.
486+
487+
:::
488+
485489
#### Changing a column data type
486490

487491
You must wrap the `ALTER TABLE` statement in a conditional block, so that subsequent runs of the

0 commit comments

Comments
 (0)