1. SQL / Говнокод #2053

    −164.9

    1. 1
    ORA-600 [12235]: Oracle process has no purpose in life!

    Даже Оракл знает что такое смысл жизни

    dim1r, 27 Октября 2009

    Комментарии (1)
  2. SQL / Говнокод #1993

    −164.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    CREATE TABLE users(
      ....
      passwd VARCHAR (32) DEFAULT NULL,
      passwd_clear VARCHAR (32) DEFAULT NULL,
    
    ....

    passwd - типа зашифрованный
    passwd_clera - типа в открытом виде ))))

    paranoid, 19 Октября 2009

    Комментарии (9)
  3. SQL / Говнокод #1942

    −154.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    create table user.profile (
      ...
      gender boolean,
      ...
    )

    Очевидно, true - это мужик :D

    Suor, 06 Октября 2009

    Комментарии (42)
  4. SQL / Говнокод #1878

    −863.7

    1. 1
    2. 2
    3. 3
    Нашёл в проекте
    SELECT DISTINCT sale_date, SUM(sale_price), buyer FROM ... 
    GROUP BY sale_date, buyer;

    DISTINCT здесь лишний

    Oleg_quadro, 21 Сентября 2009

    Комментарии (10)
  5. SQL / Говнокод #1794

    −863

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    select ...
    from ...
    where ...
                     and NVL2(l_date_from, trunc(mmt.transaction_date), l_date_from) >= NVL(l_date_from, l_date_from) 
                     and NVL2(l_date_to, trunc(mmt.transaction_date), l_date_to) <= NVL(l_date_to, l_date_to)          
    ...

    из реально работающей системы

    nxx, 09 Сентября 2009

    Комментарии (3)
  6. SQL / Говнокод #1705

    −866.9

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    CREATE TABLE [Battles] (
    	[name] [varchar] (20) NOT NULL ,
    	[date] [datetime] NOT NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Classes] (
    	[class] [varchar] (50) NOT NULL ,
    	[type] [varchar] (2) NOT NULL ,
    	[country] [varchar] (20) NOT NULL ,
    	[numGuns] [tinyint] NULL ,
    	[bore] [real] NULL ,
    	[displacement] [int] NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[Ships] (
    	[name] [varchar] (50) NOT NULL ,
    	[class] [varchar] (50) NOT NULL ,
    	[launched] [smallint] NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[Outcomes] (
    	[ship] [varchar] (50) NOT NULL ,
    	[battle] [varchar] (20) NOT NULL ,
    	[result] [varchar] (10) NOT NULL 
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[Battles] ADD 
    	CONSTRAINT [PK_Battles] PRIMARY KEY  CLUSTERED 
    	(
    		[name]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Classes] ADD 
    	CONSTRAINT [PK_Classes] PRIMARY KEY  CLUSTERED 
    	(
    		[class]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Ships] ADD 
    	CONSTRAINT [PK_Ships] PRIMARY KEY  CLUSTERED 
    	(
    		[name]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Outcomes] ADD 
    	CONSTRAINT [PK_Outcomes] PRIMARY KEY  CLUSTERED 
    	(
    		[ship],
    		[battle]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Ships] ADD 
    	CONSTRAINT [FK_Ships_Classes] FOREIGN KEY 
    	(
    		[class]
    	) REFERENCES [dbo].[Classes] (
    		[class]
    	) NOT FOR REPLICATION 
    GO
    ALTER TABLE [dbo].[Outcomes] ADD 
    	CONSTRAINT [FK_Outcomes_Battles] FOREIGN KEY 
    	(
    		[battle]
    	) REFERENCES [dbo].[Battles] (
    		[name]
    	)
    GO

    Это с sql-ex.ru , база "корабли"
    Может, упражнения там интересные,
    но сама база истинный говнокод. Почему?
    Строчка
    "В отношение Outcomes могут входить корабли, отсутствующие в отношении Ships."
    делает её говнокодом.

    lexx, 27 Августа 2009

    Комментарии (5)
  7. SQL / Говнокод #1583

    −166.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    SELECT DISTINCT B.TYPE_SID, B.ID BANNER_ID, B.WEIGHT BANNER_WEIGHT,
    B.SHOWS_FOR_VISITOR, B.FIX_CLICK, B.FIX_SHOW, B.KEYWORDS BANNER_KEYWORDS,
    C.ID CONTRACT_ID, C.WEIGHT CONTRACT_WEIGHT, C.KEYWORDS CONTRACT_KEYWORDS
    FROM b_adv_type T
    INNER JOIN b_adv_banner B ON ( B.ACTIVE='Y' and B.TYPE_SID = T.SID
    and B.STATUS_SID = 'PUBLISHED'
    and (B.FOR_NEW_GUEST is null or B.FOR_NEW_GUEST='N')
    and (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0)
    or ifnull(B.MAX_SHOW_COUNT,0)=0) and (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0)
    or ifnull(B.MAX_CLICK_COUNT,0)=0) and (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0)
    or ifnull(B.MAX_VISITOR_COUNT,0)=0) and (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_
    FROM is null or length(B.DATE_SHOW_FROM)<=0) and (B.DATE_SHOW_TO>=now()
    or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0))
    INNER JOIN b_adv_banner_2_site BS ON ( BS.BANNER_ID = B.ID and BS.SITE_ID = 'ru')
    INNER JOIN b_adv_contract C ON ( C.ID = B.CONTRACT_ID and C.ACTIVE='Y'
    and (ifnull(C.MAX_SHOW_COUNT,0)>ifnull(C.SHOW_COUNT,0)
    or ifnull(C.MAX_SHOW_COUNT,0)=0) and (ifnull(C.MAX_CLICK_COUNT,0)>ifnull(C.CLICK_COUNT,0)
    or ifnull(C.MAX_CLICK_COUNT,0)=0)  and (ifnull(C.MAX_VISITOR_COUNT,0)>ifnull(C.VISITOR_COUNT,0)
    or ifnull(C.MAX_VISITOR_COUNT,0)=0) and (C.DATE_SHOW_FROM<=now() or C.DATE_SHOW_
    FROM is null or length(C.DATE_SHOW_FROM)<=0) and (C.DATE_SHOW_TO>=now() or C.DATE_SHOW_TO is null
    or length(C.DATE_SHOW_TO)<=0))
    INNER JOIN b_adv_contract_2_site CS ON ( CS.CONTRACT_ID = B.CONTRACT_ID and CS.SITE_ID = 'ru')
    INNER JOIN b_adv_contract_2_type CT ON ( CT.CONTRACT_ID = C.ID
    and (CT.TYPE_SID = 'ALL' or CT.TYPE_SID = T.SID))
    INNER JOIN b_adv_banner_2_weekday BW ON ( BW.BANNER_ID = B.ID
    and BW.C_WEEKDAY='SUNDAY' and BW.C_HOUR = '11')
    INNER JOIN b_adv_contract_2_weekday CW ON ( CW.CONTRACT_ID = C.ID
    and CW.C_WEEKDAY='SUNDAY' and CW.C_HOUR = '11')
    LEFT JOIN b_adv_banner_2_group UG1 ON ( (UG1.BANNER_ID = B.ID and UG1.GROUP_ID in (2,1,21)) )
    LEFT JOIN b_adv_banner_2_page BP1 ON ( BP1.BANNER_ID = B.ID and BP1.SHOW_ON_PAGE='Y')
    LEFT JOIN b_adv_banner_2_page BP2 ON ( BP2.BANNER_ID = B.ID and BP2.SHOW_ON_PAGE='N'
    and '/e-store/books/index.php?SECTION_ID=145' like concat(BP2.PAGE, '%'))
    LEFT JOIN b_adv_contract_2_page CP1 ON ( CP1.CONTRACT_ID = C.ID and CP1.SHOW_ON_PAGE='Y')
    LEFT JOIN b_adv_contract_2_page CP2 ON ( CP2.CONTRACT_ID = C.ID and CP2.SHOW_ON_PAGE='N'
    and '/e-store/books/index.php?SECTION_ID=145' like concat(CP2.PAGE, '%'))
    LEFT JOIN b_adv_banner_2_stat_adv BA ON BA.BANNER_ID = B.ID
    LEFT JOIN b_adv_banner_2_country BC ON BC.BANNER_ID = B.ID WHERE T.ACTIVE = 'Y'
    and BP2.ID is null and CP2.ID is null
    and (BP1.ID is null or '/e-store/books/index.php?SECTION_ID=145' like concat(BP1.PAGE, '%'))
    and (CP1.ID is null or '/e-store/books/index.php?SECTION_ID=145' like concat(CP1.PAGE, '%'))
    and (BA.STAT_ADV_ID is null or BA.STAT_ADV_ID='0')
    and (BC.COUNTRY_ID is null or BC.COUNTRY_ID='N0')
    and ( (B.SHOW_USER_GROUP = 'Y' and UG1.GROUP_ID is not null)
    or (B.SHOW_USER_GROUP <> 'Y' and UG1.GROUP_ID is null))
    ORDER BY B.TYPE_SID desc, C.ID desc

    SQL-запрос из Битрикса

    http://ekimoff.ru/165/

    endo, 14 Августа 2009

    Комментарии (9)
  8. SQL / Говнокод #1497

    −867.6

    1. 1
    SELECT SQL_CALC_FOUND_ROWS *,cached_login as login,cached_name as uname,comment_count as ccount FROM posts p WHERE exists (select * from tags tg, tegi_zapisi tx where tg.alt_title like 'post' and tg.id_tag=tx.id_tag and tx.id_post=p.id_post) and exists (select * from tags tg, tegi_zapisi tx where tg.alt_title like 'opentomsk' and tg.id_tag=tx.id_tag and tx.id_post=p.id_post) and hide<>1 ORDER BY p.date desc, p.time desc LIMIT 210,10

    выбираем все посты с определёнными тегами или без них
    удивляемся, почему тормозит пропорционально количеству тегов

    guest, 08 Августа 2009

    Комментарии (7)
  9. SQL / Говнокод #1471

    −853.2

    1. 1
    какой нафиг код((((

    больше года пишут и поддерживают проект
    а как оказалось, в бд на 36 таблиц нет ни одного фореинг кея!
    уебаны ((((((((((

    guest, 05 Августа 2009

    Комментарии (20)
  10. SQL / Говнокод #1434

    −844

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    SELECT
    					'X' `TYPEOF`
    					,161 AS `ID`
    					,pa.ARTICUL
    					,p.PRODUCT_NAME
    					,p.PRODUCT_INSTRUCTION
    					,p.PRODUCT_WEIGHT
    					,p.PRODUCT_VOLUME
    					,p.PRODUCT_RATING
    					,pm.MEASURE
    					,b.BRAND_NAME
    					,cs.COLL_NAME COLLECTION
    					,m.MAN_NAME MANUFACTORER
    					,pst.QUANTITY
    					,p.TIMESTAMP_X AS LAST_MODIFY
    					
    					,pts.PRODUCT_NOTE
    					,pts.PRODUCT_DESCRIPTION
    					,pts.PRODUCT_IMAGE
    					,pts.PRODUCT_GALLERY
    					,pts.PRODUCT_ACTIVE
    					,pts.PRODUCT_ACTIVE_FROM
    					,pts.PRODUCT_ACTIVE_TO
    					,pts.PRODUCT_NEW
    					,pts.PRODUCT_LEADER
    					,pts.USER_ID
    					,pts.SITE_ID
    					,'X' CATEGORIES
    					,'X' FEATURES
    					,'X' RANGE_APPLICATION
    					,'X' RANGE_PRESCRIPTION
    					,'X' PRODUCT_PRICE
    					,'X' PRICE_CURRENCY
    					,'X' PRODUCT_PRICE_GROUP
    					,'X' IMAGES
    				FROM  `e_products` `p` 
    					LEFT JOIN `e_product_to_site` `pts` ON ((`pts`.`PRODUCT_ID`=161))
    					LEFT JOIN `e_product_articuls` `pa` ON ((`pa`.`PRODUCT_ID`=161)) 
    					LEFT JOIN `e_product_stock` `pst` ON ((`pst`.`PRODUCT_ID`=161)) 
    					LEFT JOIN `e_product_to_brand` `ptb` ON ((`ptb`.`BRAND_ID`=161)) 
    					LEFT JOIN `e_product_to_collection` `pcl` ON ((`pcl`.`PRODUCT_ID` = 161)) 
    					LEFT JOIN `e_product_measure` `pm` ON ((`p`.`PRODUCT_MEASURE` = `pm`.`ID`)) 
    					LEFT JOIN `e_brands` `b` ON ((`ptb`.`BRAND_ID`=`b`.`ID`)) 
    					LEFT JOIN `e_manufactorers` `m` ON ((`b`.`MAN_ID`=`m`.`ID`)) 
    					LEFT JOIN `e_collections` `cs` ON ((`cs`.`ID`=`pcl`.`COLLECTION_ID`)) 
    					LEFT JOIN `e_product_prices` `pp` ON ((`pp`.`PRODUCT_ID`=`p`.`ID`))
    
    			WHERE `p`.`ID` IN (161) AND `pts`.`SITE_ID` LIKE 's0' 
    				
    				UNION 
    				SELECT 'categories',`p`.`ID` AS `ID`
    					,'X','X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X','X','X','X','X','X','X','X','X','X'
    				    ,`ptc`.`CATEGORY_ID`
    				    ,'X','X','X','X','X','X','X'
    				FROM `e_product_to_category` `ptc` 
    					LEFT JOIN `e_products` `p` ON ((`p`.`ID`=`ptc`.`PRODUCT_ID`))
    					LEFT JOIN `e_product_categories` `pc` ON ((`pc`.`ID`=`ptc`.`CATEGORY_ID`))
    					LEFT JOIN `e_catalogs` `c` ON ((`c`.`ID`=`pc`.`CATALOG_ID`)) 
    					WHERE `ptc`.`PRODUCT_ID` IN (161)
    					 AND `c`.`SITE_ID` LIKE 's0' 
    				
    				UNION 
    				SELECT 'features',`p`.`ID` AS `ID`
    					,'X','X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X','X','X','X','X','X','X','X','X','X'
    					,'X'
    				    ,FEATURE_ID 
    				    ,'X','X','X','X','X','X'
    				FROM `e_product_catalog` `pc` 
    					LEFT JOIN `e_products` `p` ON `p`.`ID`=`pc`.`PRODUCT_ID`
    					LEFT JOIN `e_product_to_category` `ptc` ON ((`ptc`.`PRODUCT_ID`=`pc`.`PRODUCT_ID`)) 
    					LEFT JOIN `e_catalogs` `c` ON ((`c`.`ID`=`ptc`.`CATEGORY_ID`)) 
    				WHERE `pc`.`PRODUCT_ID` IN (161) AND `c`.`SITE_ID` LIKE 's0'  
    				
    				UNION 
    				
    				SELECT 'rangeapp',`p`.`ID` AS `ID`
    					,'X','X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X'
    				    ,`RANGE_APP_ID`
    				    ,'X' ,'X','X','X','X'
    				FROM `e_product_range_app` `pra` 
    					LEFT JOIN `e_products` `p` ON `p`.`ID`=`pra`.`PRODUCT_ID`
    				WHERE `PRODUCT_ID` IN (161) 
    				
    				UNION 
    				SELECT 'rangepre',`p`.`ID` AS `ID`
    					,'X','X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X','X','X','X','X','X','X','X','X','X'
    					,'X','X','X'
    				    ,`RANGE_PRE_ID`,'X','X','X','X'
    				FROM `e_product_range_pre` `prp` 
    					LEFT JOIN `e_products` `p` ON `p`.`ID`=`prp`.`PRODUCT_ID`
    				WHERE `PRODUCT_ID` IN (161)
    				
    				UNION 
    				SELECT 'prices',`p`.`ID` AS `ID`
    					,'X','X','X','X','X','X','X','X','X','X','X','X'

    guest, 28 Июля 2009

    Комментарии (2)