Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2002
    Posts
    3

    Question Unanswered: user defined datatype

    i decited to implement user-defined datatypes in my db. so i created a datatype (varchar) with notNULL-Option.
    i used this datatype in a testtable and tryed to insert a NULL-value.
    it succeeded?!?

    why does it succeed? i set notNULL = true, so i thought i couldn't insert NULL-values...

    thanx
    rulid300.

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    I've created a little test script and I can't see how that happened, maybe you can post your script. Here is mine
    Code:
    EXEC sp_addtype myData, 'VARCHAR(11)', 'NOT NULL'
    GO
    CREATE TABLE myTbl
    	(
    	id	INT 	IDENTITY(1,1),
    	col1	myData
    	)
    GO
    
    INSERT myTbl(col1) values('xxxx')
    GO
    INSERT myTbl(col1) values(NULL)
    GO
    INSERT myTbl(col1) values('NULL')
    GO
    
    SELECT * FROM myTbl
    Here is the output:

    (1 row(s) affected)

    Type added.

    (1 row(s) affected)

    Server: Msg 515, Level 16, State 2, Line 1
    Cannot insert the value NULL into column 'col1', table 'pubs.dbo.myTbl'; column does not allow nulls. INSERT fails.
    The statement has been terminated.

    (1 row(s) affected)

    id col1
    --- --------
    1 xxxx
    3 NULL

    (2 row(s) affected)


    I could insert the word "NULL" but not the value of NULL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •