Results 1 to 4 of 4

Thread: delete data

  1. #1
    Join Date
    Jan 2004
    Posts
    5

    Question Unanswered: delete data

    Hi,

    I have two tables.

    CREATE TABLE [one] (
    [roleno] [int] NOT NULL ,
    [schno] [int] NULL ,
    CONSTRAINT [PK_one] PRIMARY KEY CLUSTERED
    (
    [roleno]
    ) ON [PRIMARY] ,
    CONSTRAINT [FK_one_two] FOREIGN KEY
    (
    [schno]
    ) REFERENCES [two] (
    [schno]
    )
    ) ON [PRIMARY]
    GO

    CREATE TABLE [two] (
    [roleno] [int] NULL ,
    [schno] [int] NOT NULL ,
    CONSTRAINT [PK_two] PRIMARY KEY CLUSTERED
    (
    [schno]
    ) ON [PRIMARY] ,
    CONSTRAINT [FK_two_one] FOREIGN KEY
    (
    [roleno]
    ) REFERENCES [one] (
    [roleno]
    )
    ) ON [PRIMARY]
    GO


    (I fact i created Primary & Foreign keys after inserting data in both of these tables.)

    I want to delete data from these two tables.
    How do i do that...Any Ideas?

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401

    Re: delete data

    Originally posted by naveen_mehta
    Hi,

    I have two tables.

    CREATE TABLE [one] (
    [roleno] [int] NOT NULL ,
    [schno] [int] NULL ,
    CONSTRAINT [PK_one] PRIMARY KEY CLUSTERED
    (
    [roleno]
    ) ON [PRIMARY] ,
    CONSTRAINT [FK_one_two] FOREIGN KEY
    (
    [schno]
    ) REFERENCES [two] (
    [schno]
    )
    ) ON [PRIMARY]
    GO

    CREATE TABLE [two] (
    [roleno] [int] NULL ,
    [schno] [int] NOT NULL ,
    CONSTRAINT [PK_two] PRIMARY KEY CLUSTERED
    (
    [schno]
    ) ON [PRIMARY] ,
    CONSTRAINT [FK_two_one] FOREIGN KEY
    (
    [roleno]
    ) REFERENCES [one] (
    [roleno]
    )
    ) ON [PRIMARY]
    GO


    (I fact i created Primary & Foreign keys after inserting data in both of these tables.)

    I want to delete data from these two tables.
    How do i do that...Any Ideas?
    Code:
    ALTER TABLE ONE NOCHECK CONSTRAINT FK_one_two
    ALTER TABLE TWO NOCHECK CONSTRAINT FK_two_one
    DELETE ONE
    DELETE TWO
    ALTER TABLE ONE CHECK CONSTRAINT FK_one_two
    ALTER TABLE TWO CHECK CONSTRAINT FK_two_one
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Jan 2004
    Posts
    5
    That really works...Thanks a ton....

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    You could similarly use the alter statements while inserting data if you do not want to check for constraints
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

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