sql判断是否存在某表
select * from information_schema.key_column_usage where TABLE_NAME='BankPid' select * from sysobjects
C#判断是否存在某表,并创建该表
string tip = pid.Substring(pid.Length-2,2); string sql = "select count(*) from information_schema.key_column_usage where TABLE_NAME='PidName" + tip + "'"; if (db.Database.SqlQuery<int>(sql).FirstOrDefault()==0) { db.Database.ExecuteSqlCommand("SELECT * into PidName" + tip + " FROM PidName WHERE 1=2;ALTER TABLE PidName" + tip + " ADD CONSTRAINT PK_PidName" + tip + " PRIMARY KEY (Pid)"); }