Toon posts:

[MSSQL] Probleem met BIT datatype

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo

Ik ben in een bedrijf wat aanpassingen aan het uitvoeren op een antieke MSSQL 6.5 database. Nu moet ik wat columns toevoegen aan een tabel. Geen probleem. Maar zo gauw ik het BIT datatype gebruik komt daar verandering in
code:
1
ALTER table taxaties ADD definitief BIT

of
code:
1
ALTER table taxaties ADD definitief BIT not null

ALTER TABLE only allows columns to be added which can contain nulls. Column 'definitief' cannot be added to table 'taxaties' because it does not allow nulls.

Dus dan maar
code:
1
ALTER table taxaties ADD definitief BIT null

Column or parameter #1: -- can't specify Null values on a column of type BIT.

grrr

De standaard syntax werkt hier dus niet. Ik kan het niet testen maar volgens mij werkt het wel op hogere versies. Toch staat hier :

http://msdn.microsoft.com...lref/ts_sp_da-di_5c8c.asp

"bit columns created without an explicit NULL or NOT NULL option in CREATE TABLE or ALTER TABLE are created as NOT NULL". Het moet dus kunnen. Let wel, het woord "column" mag je niet gebruiken in 6.5 :|

  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
ALTER table taxaties ADD definitief BIT not null DEFAULT 0

  • klinz
  • Registratie: Maart 2002
  • Laatst online: 21-05 09:01

klinz

weet van NIETS

In SQL server 6.5 mag dat gewoon niet.

Volgens mij moet je een nare omweg gebruiken, waarbij je de kolom eerst als int creeert en populeert. Vervolgens omzetten naar een bit. Naar maar waar.

Je kunt natuurlijk ook de tabel opnieuw creeren en vervolgens de data overpompen.

  • EfBe
  • Registratie: Januari 2000
  • Niet online
Volgens mij kan het met een default definitie erbij, zoals bigbeng aangeeft.

Creator of: LLBLGen Pro | Camera mods for games
Photography portfolio: https://fransbouma.com


  • Annie
  • Registratie: Juni 1999
  • Laatst online: 25-11-2021

Annie

amateur megalomaan

Verwijderd schreef op 31 augustus 2004 @ 17:11:
De standaard syntax werkt hier dus niet. Ik kan het niet testen maar volgens mij werkt het wel op hogere versies. Toch staat hier :

http://msdn.microsoft.com...lref/ts_sp_da-di_5c8c.asp

"bit columns created without an explicit NULL or NOT NULL option in CREATE TABLE or ALTER TABLE are created as NOT NULL". Het moet dus kunnen. Let wel, het woord "column" mag je niet gebruiken in 6.5 :|
/mosterd-na-de-maaltijd:

Books Online is je vriend.
NULL | NOT NULL

Specifies whether the column can accept null values. Columns that do not allow null values can be added with ALTER TABLE only if they have a default specified. A new column added to a table must either allow null values, or the column must be specified with a default value.

If the new column allows null values and no default is specified, the new column contains a null value for each row in the table. If the new column allows null values and a default definition is added with the new column, the WITH VALUES option can be used to store the default value in the new column for each existing row in the table.

If the new column does not allow null values, a DEFAULT definition must be added with the new column, and the new column automatically loads with the default value in the new columns in each existing row.
Nu maar hopen dat MSSQL6.5 er ook zo over denkt.

Today's subliminal thought is:


Verwijderd

in 6.5 kon je gewoon geen BIT veld ADDen aan een tabel, een van de beperkingen van deze versie. Je zult hem dan eerst moeten droppen en recreaten.... zie ook bv http://www.avdf.com/june98/art_ot002.html

Verwijderd

Topicstarter
Verwijderd schreef op 01 september 2004 @ 08:01:
in 6.5 kon je gewoon geen BIT veld ADDen aan een tabel, een van de beperkingen van deze versie. Je zult hem dan eerst moeten droppen en recreaten.... zie ook bv http://www.avdf.com/june98/art_ot002.html
Dit lijkt inderdaad te kloppen. "Default 0" heeft niet het gewenste effect in 6.5.

Ik denk dat ik er maar een int default 0 van maak. Daarna ga ik die lui hier eens van een upgrade overtuigen.

bedankt voor alle reacties
Pagina: 1