Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2004
    Posts
    3

    Talking Unanswered: help needed on a silly query :P

    hi ...
    i m a new member
    i want a help on this query(new user of sql )
    yaa and the query is

    create a rule and attach it to the service_code(column) of airline_service(Table) alow only the values 'cc','n' and 'wc' to be entered into the column

    plz tell mee... ..i wlll be gr8 fulllllllllllllllllllllllllllllllll

  2. #2
    Join Date
    Feb 2003
    Location
    Milano, Italy
    Posts
    80
    I suggest you to create a CHECK CONSTRAINT instead of a rule:

    ALTER TABLE dbo.airline_service
    ADD CONSTRAINT chk_servicecode CHECK (service_code IN ('cc', 'n', 'wc'))

    Davide Mauri
    http://www.davidemauri.it
    Davide Mauri
    http://www.davidemauri.it

  3. #3
    Join Date
    Feb 2004
    Posts
    492
    You could create a trigger or a check. I think a check is more likely what you'd like, fe:

    use monkey
    go

    create table table1 (mycolumn varchar(10))
    go

    alter table table1 with check
    add constraint df__myrule check
    ( mycolumn not in ('yes', 'allowed'))
    go

    insert into table1 (mycolumn) values ('yes')
    insert into table1 (mycolumn) values ('no')
    go

    select *
    from table1


    drop table table1
    go


    See BOL on CHECK

    EDIT: sniped!

  4. #4
    Join Date
    Aug 2004
    Posts
    3

    thnk you

    thank youuuuuuuuuuuuuuuuuuuuuuu

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    I hope your professor gives you full credit for that, but next time try to do your own homework first.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Aug 2004
    Posts
    15
    I doubt if the Professor will give a credit!

    He asked for a rule so it should be:

    CREATE RULE list_rule
    AS
    @list IN ('cc', 'n', 'wc')

    nomis

  7. #7
    Join Date
    Feb 2003
    Location
    Milano, Italy
    Posts
    80
    That's for sure, but rules are to be considered deprecated, only for backward compatibility. So the CHECK solution is really better. :-)

    Anyway, after adding the rule it must be binded with sp_bindrule
    Davide Mauri
    http://www.davidemauri.it

Posting Permissions

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