代码之家  ›  专栏  ›  技术社区  ›  Spredzy

正确命名表的ID字段

  •  2
  • Spredzy  · 技术社区  · 14 年前

    我目前正在读JoeCelko写的“SQL编程风格”一书。

    在第一章中,在“开发标准化的后缀”一段中,他为ID列声明:

    “_id”=标识符。它是独一无二的 模式并引用一个实体 它出现在模式中的任何位置。

    8 回复  |  直到 14 年前
        1
  •  1
  •   onedaywhen    14 年前

        2
  •  3
  •   Walter Mitty    14 年前

        3
  •  2
  •   David    14 年前

        4
  •  1
  •   John Hartsock    14 年前

    Select
      * 
    FROM table1
    Inner join table2 on table1ID = table2ID
    

    Select
      * 
    FROM table1
    Inner join table2 on ID = ID
    

        5
  •  1
  •   Riedsio    14 年前

        6
  •  0
  •   HLGEM    14 年前

    create table #test1 (id int identity, test varchar(10))
    create table #test2 (id int identity, test varchar(10))
    create table #test3 (id int identity, test varchar(10))
    
    insert #test1
    values ('hi')
    insert #test1
    values ('hello')
    insert #test2
    values ('hi there')
    insert #test3
    values ('hello')
    insert #test3
    values ('hi')
    select * 
    from #test1 t1
    join #test2 t2
        on t1.id = t2.id
    join #test3  t3
        on t1.id = t2.id    
    select * 
    from #test1 t1
    join #test2 t2
        on t1.id = t2.id
    join #test3  t3
        on t1.id = t3.id        
    
    Drop table #test1
    drop table #test2
    drop table #test3   
    Go
    
    create table #test1 (t1id int identity, test varchar(10))
    create table #test2 (t2id int identity, test varchar(10))
    create table #test3 (t3id int identity, test varchar(10))   
    
    
        insert #test1
        values ('hi')
        insert #test1
        values ('hello')
        insert #test2
        values ('hi there')
        insert #test3
        values ('hello')
        insert #test3
        values ('hi')
    
    select * 
    from #test1 t1
    join #test2 t2
        on t1.t1id = t2.t2id
    join #test3 t3
        on t1.t1id = t3.t3id    
    
    select * 
    from #test1 t1
    join #test2 t2
        on t1.t1id = t2.t2id
    join #test3 t3
        on t1.t1id = t2.t3id    
    
        Drop table #test1
        drop table #test2
        drop table #test3   
    

        7
  •  0
  •   Larry Lustig    14 年前

        8
  •  0
  •   Josh    14 年前