无论我尝试使用我的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
答案 0 :(得分:2)
ALTER TABLE [{0}] ADD [salvationID] nvarchar(19) NOT NULL DEFAULT ''