sql Constraints

Discussion in 'Databases' started by Silver89, Jan 25, 2010.

  1. #1
    Hi,

    I'm looking into setting constraints with an sql query instead of visually in programs such as sqlYog.

    My question is what (if any) is the difference between doing:

    
    CREATE TABLE test (
    test_name		char(20),
    test_email		varchar2(20),
    test_tel_no		number(11),
    CONSTRAINT test_unique UNIQUE (test_name)
    );
    
    Code (markup):
    and

    
    CREATE TABLE test (
    test_name		char(20)		unique,
    test_email		varchar2(20),
    test_tel_no		number(11)
    );
    
    Code (markup):
    Thanks
     
    Silver89, Jan 25, 2010 IP
  2. alextera

    alextera Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    They result in the same table structure ;)
    Cheers
     
    alextera, Jan 26, 2010 IP
    Silver89 likes this.
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Both the syntax will add UNIQUE key on test_name field. You can use either of them. I would however suggest to use proper syntax of adding index.
     
    mastermunj, Jan 27, 2010 IP