2013-03-29 43 views
0

我不斷收到「解析查詢時出現錯誤」,無論我用我的DDL嘗試什麼。SQL Server CE的DDL解析器是非常挑剔的,但祕密的是它發現錯誤

因此,我需要SQL的SQL-Server-CE風格的專家告訴我以下哪個方法是首選方法(或其他方法,很可能)。請注意,我不擔心 「SQL注入」 與這些字符串格式元素:

1)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19)", tablename); 
ddl = string.Format("UPDATE {0} SET redemptionID = ''", tablename); 

2)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL", tablename); 
ddl = string.Format("UPDATE {0} SET redemptionID = ''", tablename); 
//explicitly supplying the empty string 

3)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL", tablename); 
//assuming the empty string is supplied automatically 

4 )

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL WITH DEFAULT", tablename); 
//assuming it automatically provides an empty string val 

5)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL WITH DEFAULT ''", tablename); 
//specifying the default val explicitly - an empty string 

6)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL WITH DEFAULT {1}", tablename, string.empty); 
//specifying the default val explicitly - an empty string via a string format element 

7)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL DEFAULT ''", tablename); 
//omitting the "WITH" keyword and specifying the default val explicitly - an empty string 

8)

string ddl = string.Format("ALTER TABLE {0} ADD salvationID nvarchar(19) NOT NULL DEFAULT {1}", tablename, string.empty); 
//omitting the "WITH" keyword and specifying the default val explicitly - an empty string via a string format element 

回答

2
ALTER TABLE [{0}] ADD [salvationID] nvarchar(19) NOT NULL DEFAULT '' 

http://msdn.microsoft.com/en-us/library/ms174123.aspx

+0

謝謝;好東西我支持自己的東西不同於我的選擇之一。 –

+0

這是否適用於所有查詢和ddl? IOW,應該是這樣的: string.Format(「SELECT COUNT(*)FROM {0}」,tableName); be: string.Format(「SELECT COUNT(*)FROM [{0}]」,tableName); ? 我仍然遇到可怕的問題,「解析查詢時出現錯誤」,並且不得不查看每條SQL語句以查看問題可能是什麼。 –

+0

是的,如果表名有兩個或更多的單詞,否則它不是必需的 – ErikEJ