日期:2014-05-17  浏览次数:20377 次

求解释sql基础~
public DataTable GetList(int top)
  {
  StringBuilder strSql = new StringBuilder();
  string addsql = "top "+top;
  if (top <= 0)
  {
  addsql = "";
  }

  strSql.Append("select " + addsql + " a.ID,a.Author,a.TypeId,a.[Subject],a.[Content],a.[Count],a.date,b.Type ");
  strSql.Append(" FROM Article a join [type] b on a.TypeId = b.ID order by a.ID desc");
  return SQLHelper.ExecuteTable(strSql.ToString());
  }


addSql为什么是一个字段,表示什么意思?a.和b.又是什么?from大小写没关系?数据库中的content和subject都没中括号的,而在代码中加了中括号?count在数据库中加了中括号我理解~

------解决方案--------------------
这是拼SQL语句,假如参数Int top=3,则SQL语句为:
SQL code
select top 3 a.ID,a.Author,a.TypeId,a.[Subject],a.[Content],a.[Count],a.date,b.Type FROM Article a join [type] b on a.TypeId = b.ID order by a.ID desc