如果表存在,我嘗試使用C#刪除Teradata數據庫中的表。teradata中的表刪除表
cmd.CommandText = string.Format("IF EXISTS
(SELECT * FROM sysobjects WHERE type = 'U' AND name = '{0}')
BEGIN DROP TABLE '{0}' END", Customer.TableName);
cmd.ExecuteNonQuery();
但上面總是失敗:
{"[Teradata Database] [3706] Syntax error: expected something between the beginning of the request and the 'IF' keyword."}
二碼我想,下面的代碼工作!
cmd.CommandText = "select count (*) from Customer.TableName";
reader = cmd.ExecuteReader();
if (reader.FieldCount > 0)
{
reader.Close();
cmd.CommandText = "Drop table Customer.TableName";
reader = cmd.ExecuteReader();
}
但是,它只有當表格存在時才起作用。如果表Customer.TableName不存在,那麼就會接受這種
"select count (*) from Customer.TableName";
reader = cmd.ExecuteReader();
對不起工作,沒有工作。如果我只運行SELECT 1 FROM dbc.tables WHERE databasename ='John'AND tablename ='ctry',那麼它會返回一些數據。但它失敗了,當我申請IF EXISTS()然後下降表'ctry' – VeecoTech
什麼是錯誤? –
{「[Teradata Database] [3706]語法錯誤:預計在請求開頭和'IF'關鍵字之間有一些東西。」} – VeecoTech