2013-10-26 228 views
8

我之前在Yii Framework中使用MS SQL Server 2005,並在那裏創建表和存儲過程。但現在我把我的數據庫轉移到MS SQL Server 2008 R2,當我試圖保存長長的字符串,然後它給了我最大長度的錯誤,而我已經設置該列的數據類型爲「文本」之後,我取而代之的是「varchar(max)」,但沒有解決方案。以......開頭的標識符太長。最大長度爲128

請給我一個解決方案如何解決這個問題。我正在執行以下查詢:

update hotel 
set hotel_policy = 
    "Overview of Park Central New York - New York 
    This hotel is making improvements. 
     The property is undergoing renovations. The following areas are affected: 
     Bar/lounge 
     Business center 
     Select guestrooms 

    Every effort will be made to minimize noise and disturbance. 
    Occupying a Beaux Arts building dating to 1927, Park Central New York Hotel is within a block of famed concert venue Carnegie Hall and within a 5-minute walk of Manhattan’s world-renowned Broadway theater district. Prefer the great outdoors to the Great White Way? Central Park is just 3 blocks from the hotel. There, you can rent a rowboat at the lake, play a game of tennis, or visit the Central Park Zoo. The international boutiques and flagship department stores of Fifth Avenue start within a 10-minute walk of the hotel. For travel to sights farther afield, there are 7 subway lines located within 3 blocks of the Park Central. 
    The hotel has a snack bar for guests' convenience, and coffee and tea in the lobby. 
    Retreat to your guestroom and sink into a bed with a pillowtop mattress and down comforter and pillows. Need to check email or finish up some work? You’ll find a desk with an ergonomic chair and wireless high-speed Internet access (surcharge). Unwind with a video game (surcharge) on the flat-panel HDTV." 

where hotel_id = 1 

我搜索了很多,但我找到的C#解決方案對我無用。

謝謝!

回答

15

根據ANSI SQL標準,雙引號被使用(如果必要)爲對象標識符(例如:UPDATE "hotel" ...),而不是作爲字符串分隔符("Overview of Park Central ...")。SQL Server有這種行爲時QUOTED_IDENTIFIERON

編輯1: 單和雙引號,作爲分隔符的對象標識符(包括列別名)的用法如下所述:

     Delimiter Delimiter 
         for   for 
SET QUOTED_IDENTIFIER Object ID Alias ID  StringDelimiter 
ON      " or []  " or ' or [] ' 
OFF      []   " or ' or [] " or ' 
  • ON然後雙引號可用作對象標識符(包括列別名)的分隔符,單引號用作字符串文字和/或列別名(SELECT Column1 AS 'Alias1' ....)標識符的分隔符。
  • OFF然後雙引號可用作列別名(SELECT Column1 AS "Alias1" ...)的分隔符和字符串文本的分隔符(SELECT "String1" AS Alias1 ...)。單引號可以用作字符串分隔符和列別名的分隔符(SELECT Column1 AS Alias1 ...)。

使用,而不是單引號:

update hotel 
set hotel_policy = 'Overview of Park Central ...' 
where hotel_id = 1 
3

如果你不想改變雙引號單引號加在之後的腳本

SET QUOTED_IDENTIFIER OFF 
SET ANSI_NULLS ON 
+0

沒有乞討兩條線,即並不能解決問題。 – Zerubbabel