Hugo Kornelis (10/12/2010)
The short explanation is that, within a [delimited identifier], you have to double the ] to get a single ] character.
Ah, that makes sense... Well, it doesn't completely, since I would expect that the opening square bracket should be escaped as well then for conistentcy. But whatever
Still, SMO seems to have some issues dropping the table. But it looks like it's not the delimiter that is causing the problem, but a unix like linefeed instead of carriage return with linefeed between the "statements" in the name.
Following is the statement that returns no rows because of the linefeeds when trying to drop the table via SSMS (recorded via profiler). The linefeeds (0x0A) can be seen by converting to varbinary(max) for example.
SCHEMA_NAME(tbl.schema_id) AS [Schema],
tbl.name AS [Name]
sys.tables AS tbl
insert into Vararray(i) SELECT 1
while 1 = 1' and SCHEMA_NAME(tbl.schema_id)=N'dbo'