Altering a column: null to not null

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Altering a column: null to not null

Message par ForumBot »

Altering a column: null to not null
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Altering a column: null to not null

Message par ForumBot »

First, make all current `NULL` values disappear:

```
UPDATE [Table] SET [Column]=0 WHERE [Column] IS NULL

```

Then, update the table definition to disallow "NULLs":

```
ALTER TABLE [Table] ALTER COLUMN [Column] INTEGER NOT NULL

```
Répondre

Revenir à « SQL Server »