SQL

  • SQLWinther

    SSCertifiable

    Points: 5946

    +1, but the answers "depends" on Cascades and nullability. This i completely correct (even if I don't like it)

    CREATE TABLE dbo.a

    (id INT PRIMARY KEY, NAMN VARCHAR(19))

    CREATE TABLE dbo.b

    (

    id INT NULL, value int

    )

    ALTER TABLE dbo.b WITH CHECK ADD CONSTRAINT fk FOREIGN KEY (id) REFERENCES dbo.a(id)

    INSERT INTO dbo.b (id, value) VALUES(NULL,1)

    By allowing null on the foreign key column, you'll end up with records without relation to parent table and it's generally a bad practice.

    /Håkan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

Viewing post 61 (of 61 total)

You must be logged in to reply to this topic. Login to reply