Im trying to copy a table structure in winforms app in C# and i always gets the error invalid syntax which is explained below : This is my code
con.Open();
cmd.Connection =con;
cmd.CommandText="Create table temp as select * from Class";
cmd.ExecuteNonQuery();
con.Close();
and the error statement shows Incorrect syntax near 'Select' and Incorrect syntax near class.
答案 0 :(得分:0)
应该是,
cmd.CommandText="Create TABLE temp AS (select * from Class)";
答案 1 :(得分:0)
您无法执行此查询,因为"选择表格"有主键或索引。
试试这个:
CREATE TABLE temp SELECT * FROM class CREATE INDEX index_column ON temp(index_column);
重要的是要注意,如果表格有主键,则需要运行另一个查询"更改表格。"并设置表的主键列。
答案 2 :(得分:-1)
试试这个:
cmd.CommandText="Create TABLE temp select * from Class";