2007年12月10日
一、数据库为:menu(menuId<pk>、menuName、parentMenuId、pageUrl、remark);
二、左侧菜单:
1、leftmenu.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LeftMenu.ascx.cs" Inherits="LeftMenu" %>
<link href="css/leftmenu.css" type="text/css" rel="stylesheet" />
<script src="js/leftmenu.js" type="text/javascript"></script>
<div id="divContain" runat="server" style="width:100px; vertical-align:top; display:block;">
</div>
2、leftmenu.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using BL;
using System.Text;
public partial class LeftMenu : System.Web.UI.UserControl
{
private string _target="_top";//导航栏的目标
public string Target
{
get { return _target; }
set { _target = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder menuString = new StringBuilder();
MenuBL menuBl = new MenuBL();
//获取根结点,即父结点为0的结点
List<MenuEntity> menus = menuBl.QueryMenu(0);
//动态加载父菜单
foreach (MenuEntity menu in menus)
{
menuString.Append("<div id='menu");
menuString.Append(menu.MenuId);
menuString.Append("' class='parentMenu' onmouseover='parentMenuOver(menu");
menuString.Append(menu.MenuId);
menuString.Append(")' onmouseout='parentMenuOut(menu");
menuString.Append(menu.MenuId);
menuString.Append(")' onClick='parentMenuClick(menu");
menuString.Append(menu.MenuId);
menuString.Append(")'>");
menuString.Append(menu.MenuName);
menuString.Append("</div>");
//加载子菜单
List<MenuEntity> sonMenus = menuBl.QueryMenu(menu.MenuId);
if (sonMenus.Count > 0)
{
menuString.Append("<div id='sonmenu" + menu.MenuId + "' class='sonMenu'>");
menuString.Append("<ul>");
foreach (MenuEntity sonMenu in sonMenus)
{
menuString.Append("<li id='li");
menuString.Append(sonMenu.MenuId);
menuString.Append("' onmouseover='liOver(li");
menuString.Append(sonMenu.MenuId);
menuString.Append(")' onmouseout='liOut(li");
menuString.Append(sonMenu.MenuId);
menuString.Append(")' onclick=\"liClick('");
menuString.Append(sonMenu.PageUrl);
menuString.Append("','");
menuString.Append(Target);
menuString.Append("')\">");
//menuString.Append("<a href='");
//menuString.Append(sonMenu.PageUrl);
//menuString.Append("' id='");
//menuString.Append(sonMenu.MenuId);
//menuString.Append("' target='");
//menuString.Append(Target);
//menuString.Append("'>");
menuString.Append(sonMenu.MenuName);
//menuString.Append("</a>");
menuString.Append("</li>");
}
menuString.Append("</ul></div>");
}
}
this.divContain.InnerHtml = menuString.ToString();
}
}
3、leftmenu.css
.parentMenu
{
background-color:#CCCCCC;
cursor:hand;
width:100px;
}
.parentMenuOver
{
background-color:#999999;
cursor:hand;
}
.parentMenuOut
{
background-color:#CCCCCC;
cursor:hand;
}
.sonMenu
{
background-color:#CCCCCC;
display:none;
}
.sonMenuSel
{
background-color:#999999;
}
.view
{
display:block;
}
.hidden
{
display:none;
}
ul
{
margin:0px 0px 0px 0px;
}
li
{
list-style-type:none;
width:100px;
cursor:hand;
}
div
{
margin:0px 0px 0px 0px;
padding:0px 0px 0px 0px;
}
.liOver
{
background-color:#E8E8E8;
}
.liOut
{
background-color:#F7F7F7;
}
a
{
width:100px;
}
4、leftmenu.js
//当点击父菜单时调用的函数
function parentMenuClick(menuId)
{
if(document.getElementById("son"+menuId.id).className=="view")
{
document.getElementById("son"+menuId.id).className="hidden";
}
else
{
document.getElementById("son"+menuId.id).className="view";
}
}
//移动到父菜单时调用
function parentMenuOver(menuId)
{
document.getElementById(menuId.id).className="parentMenuOver";
}
//移出父菜单时调用
function parentMenuOut(menuId)
{
document.getElementById(menuId.id).className="parentMenuOut";
}
////移动到子菜单时调用
//function sonMenuOver(sonMenuId)
//{
// document.getElementById(sonMenuId.id).className="view";
//}
////移出子菜单时调用
//function sonMenuOut(sonMenuId)
//{
// document.getElementById(sonMenuId.id).className="hidden";
//}
//移动到子菜单项时调用
function liOver(liId)
{
document.getElementById(liId.id).className="liOver";
}
//移出子菜单项时调用
function liOut(liId)
{
document.getElementById(liId.id).className="liOut";
}
//点击子菜单时调用
function liClick(pageUrl,target)
{
target.location.href=pageUrl;
}
三、顶部菜单
1、topmenu.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TopMenu.ascx.cs" Inherits="TopMenu" %>
<link href="css/topmenu.css" type="text/css" rel="stylesheet" />
<script src="js/topmenu.js" type="text/javascript"></script>
<div id="divContain_top" runat="server" style="width:100px; vertical-align:top; display:block;">
</div>
2、topmenu.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using BL;
using System.Text;
public partial class TopMenu : System.Web.UI.UserControl
{
private string _target = "_top";//导航栏的目标
public string Target
{
get { return _target; }
set { _target = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder menuString = new StringBuilder();
StringBuilder jsArray = new StringBuilder();
jsArray.Append("<script type='text/javascript'>");
jsArray.Append("var parentArray=new Array();");
MenuBL menuBl = new MenuBL();
//获取根结点,即父结点为0的结点
List<MenuEntity> menus = menuBl.QueryMenu(0);
menuString.Append("<table id='menu'><tr>");
//动态加载父菜单
int count = 0;
foreach (MenuEntity menu in menus)
{
menuString.Append("<td id='menu");
menuString.Append(menu.MenuId);
menuString.Append("_top' class='parentMenu_top' onmouseover='parentMenuOver_top(menu");
menuString.Append(menu.MenuId);
menuString.Append("_top)' onmouseout='parentMenuOut_top(menu");
menuString.Append(menu.MenuId);
menuString.Append("_top)'>");
menuString.Append(menu.MenuName);
menuString.Append("</td>");
jsArray.Append("parentArray[");
jsArray.Append(count);
jsArray.Append("]='sonmenu");
jsArray.Append(menu.MenuId);
jsArray.Append("_top';");
count++;
}
menuString.Append("</tr></table>");
//加载子菜单
foreach (MenuEntity menu in menus)
{
List<MenuEntity> sonMenus = menuBl.QueryMenu(menu.MenuId);
if (sonMenus.Count > 0)
{
menuString.Append("<div id='sonmenu" + menu.MenuId + "_top' class='sonMenu_top'");
menuString.Append("style=' z-index:1;position:absolute;'");
menuString.Append(">");
menuString.Append("<ul>");
foreach (MenuEntity sonMenu in sonMenus)
{
menuString.Append("<li id='li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top' class='li_top' onmouseover='liOver_top(li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top)' onmouseout='liOut_top(li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top)' onclick=\"liClick_top('");
menuString.Append(sonMenu.PageUrl);
menuString.Append("','");
menuString.Append(Target);
menuString.Append("')\">");
menuString.Append(sonMenu.MenuName);
menuString.Append("</li>");
}
menuString.Append("</ul></div>");
}
}
jsArray.Append("</script>");
menuString.Append(jsArray.ToString());
this.divContain_top.InnerHtml = menuString.ToString();
}
}
3、css
.parentMenu_top
{
background-color:#CCCCCC;
cursor:hand;
width:100px;
}
.parentMenuOver_top
{
background-color:#999999;
cursor:hand;
}
.parentMenuOut_top
{
background-color:#CCCCCC;
}
.sonMenu_top
{
display:none;
}
.li_top
{
background-color:#E8E8E8;
}
.sonMenuSel_top
{
background-color:#999999;
}
.view_top
{
display:inline-block;
}
.hidden_top
{
display:none;
}
.liOver_top
{
background-color:#E8E8E8;
}
.liOut_top
{
background-color:#F7F7F7;
}
li
{
height:20px;
width:100px;
}
4、topmenu.js
//当点击父菜单时调用的函数
function parentMenuClick_top(menuId)
{
var len=parentArray.length;
for( i=0;i<len;i++)
{
document.getElementById(parentArray[i]).className="hidden_top";
}
document.getElementById("son"+menuId.id).className="view_top";
}
//移动到父菜单时调用
function parentMenuOver_top(menuId)
{
document.getElementById(menuId.id).className="parentMenuOver";
parentMenuClick_top(menuId);
}
//移出父菜单时调用
function parentMenuOut_top(menuId)
{
document.getElementById(menuId.id).className="parentMenuOut";
}
//移动到子菜单项时调用
function liOver_top(liId)
{
document.getElementById(liId.id).className="liOver";
}
//移出子菜单项时调用
function liOut_top(liId)
{
document.getElementById(liId.id).className="liOut";
}
//点击子菜单时调用
function liClick_top(pageUrl,target)
{
if(target!="_top"&&target!="_self"&&target!="_parent"&&target!="_blank")
{
eval(target).location.href=pageUrl;
}
}
//控件的加载事件,用于子菜单的位置
function load()
{
var len=parentArray.length;
for( i=0;i<len;i++)
{
var left=0;
var top=0;
//获取父菜单的位置
var obj=document.getElementById(parentArray[i].substring(3,parentArray[i].length));
left+=obj.offsetLeft;
top+=obj.offsetTop;
while(obj = obj.offsetParent){
left += obj.offsetLeft;
top +=obj.offsetTop;
}
document.getElementById(parentArray[i]).style.left=left;
document.getElementById(parentArray[i]).style.top=top+20;
}
}
//自动加载
window.onload=load;
一、数据库为:menu(menuId<pk>、menuName、parentMenuId、pageUrl、remark);
二、左侧菜单:
1、leftmenu.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LeftMenu.ascx.cs" Inherits="LeftMenu" %>
<link href="css/leftmenu.css" type="text/css" rel="stylesheet" />
<script src="js/leftmenu.js" type="text/javascript"></script>
<div id="divContain" runat="server" style="width:100px; vertical-align:top; display:block;">
</div>
2、leftmenu.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using BL;
using System.Text;
public partial class LeftMenu : System.Web.UI.UserControl
{
private string _target="_top";//导航栏的目标
public string Target
{
get { return _target; }
set { _target = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder menuString = new StringBuilder();
MenuBL menuBl = new MenuBL();
//获取根结点,即父结点为0的结点
List<MenuEntity> menus = menuBl.QueryMenu(0);
//动态加载父菜单
foreach (MenuEntity menu in menus)
{
menuString.Append("<div id='menu");
menuString.Append(menu.MenuId);
menuString.Append("' class='parentMenu' onmouseover='parentMenuOver(menu");
menuString.Append(menu.MenuId);
menuString.Append(")' onmouseout='parentMenuOut(menu");
menuString.Append(menu.MenuId);
menuString.Append(")' onClick='parentMenuClick(menu");
menuString.Append(menu.MenuId);
menuString.Append(")'>");
menuString.Append(menu.MenuName);
menuString.Append("</div>");
//加载子菜单
List<MenuEntity> sonMenus = menuBl.QueryMenu(menu.MenuId);
if (sonMenus.Count > 0)
{
menuString.Append("<div id='sonmenu" + menu.MenuId + "' class='sonMenu'>");
menuString.Append("<ul>");
foreach (MenuEntity sonMenu in sonMenus)
{
menuString.Append("<li id='li");
menuString.Append(sonMenu.MenuId);
menuString.Append("' onmouseover='liOver(li");
menuString.Append(sonMenu.MenuId);
menuString.Append(")' onmouseout='liOut(li");
menuString.Append(sonMenu.MenuId);
menuString.Append(")' onclick=\"liClick('");
menuString.Append(sonMenu.PageUrl);
menuString.Append("','");
menuString.Append(Target);
menuString.Append("')\">");
//menuString.Append("<a href='");
//menuString.Append(sonMenu.PageUrl);
//menuString.Append("' id='");
//menuString.Append(sonMenu.MenuId);
//menuString.Append("' target='");
//menuString.Append(Target);
//menuString.Append("'>");
menuString.Append(sonMenu.MenuName);
//menuString.Append("</a>");
menuString.Append("</li>");
}
menuString.Append("</ul></div>");
}
}
this.divContain.InnerHtml = menuString.ToString();
}
}
3、leftmenu.css
.parentMenu
{
background-color:#CCCCCC;
cursor:hand;
width:100px;
}
.parentMenuOver
{
background-color:#999999;
cursor:hand;
}
.parentMenuOut
{
background-color:#CCCCCC;
cursor:hand;
}
.sonMenu
{
background-color:#CCCCCC;
display:none;
}
.sonMenuSel
{
background-color:#999999;
}
.view
{
display:block;
}
.hidden
{
display:none;
}
ul
{
margin:0px 0px 0px 0px;
}
li
{
list-style-type:none;
width:100px;
cursor:hand;
}
div
{
margin:0px 0px 0px 0px;
padding:0px 0px 0px 0px;
}
.liOver
{
background-color:#E8E8E8;
}
.liOut
{
background-color:#F7F7F7;
}
a
{
width:100px;
}
4、leftmenu.js
//当点击父菜单时调用的函数
function parentMenuClick(menuId)
{
if(document.getElementById("son"+menuId.id).className=="view")
{
document.getElementById("son"+menuId.id).className="hidden";
}
else
{
document.getElementById("son"+menuId.id).className="view";
}
}
//移动到父菜单时调用
function parentMenuOver(menuId)
{
document.getElementById(menuId.id).className="parentMenuOver";
}
//移出父菜单时调用
function parentMenuOut(menuId)
{
document.getElementById(menuId.id).className="parentMenuOut";
}
////移动到子菜单时调用
//function sonMenuOver(sonMenuId)
//{
// document.getElementById(sonMenuId.id).className="view";
//}
////移出子菜单时调用
//function sonMenuOut(sonMenuId)
//{
// document.getElementById(sonMenuId.id).className="hidden";
//}
//移动到子菜单项时调用
function liOver(liId)
{
document.getElementById(liId.id).className="liOver";
}
//移出子菜单项时调用
function liOut(liId)
{
document.getElementById(liId.id).className="liOut";
}
//点击子菜单时调用
function liClick(pageUrl,target)
{
target.location.href=pageUrl;
}
三、顶部菜单
1、topmenu.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TopMenu.ascx.cs" Inherits="TopMenu" %>
<link href="css/topmenu.css" type="text/css" rel="stylesheet" />
<script src="js/topmenu.js" type="text/javascript"></script>
<div id="divContain_top" runat="server" style="width:100px; vertical-align:top; display:block;">
</div>
2、topmenu.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using BL;
using System.Text;
public partial class TopMenu : System.Web.UI.UserControl
{
private string _target = "_top";//导航栏的目标
public string Target
{
get { return _target; }
set { _target = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder menuString = new StringBuilder();
StringBuilder jsArray = new StringBuilder();
jsArray.Append("<script type='text/javascript'>");
jsArray.Append("var parentArray=new Array();");
MenuBL menuBl = new MenuBL();
//获取根结点,即父结点为0的结点
List<MenuEntity> menus = menuBl.QueryMenu(0);
menuString.Append("<table id='menu'><tr>");
//动态加载父菜单
int count = 0;
foreach (MenuEntity menu in menus)
{
menuString.Append("<td id='menu");
menuString.Append(menu.MenuId);
menuString.Append("_top' class='parentMenu_top' onmouseover='parentMenuOver_top(menu");
menuString.Append(menu.MenuId);
menuString.Append("_top)' onmouseout='parentMenuOut_top(menu");
menuString.Append(menu.MenuId);
menuString.Append("_top)'>");
menuString.Append(menu.MenuName);
menuString.Append("</td>");
jsArray.Append("parentArray[");
jsArray.Append(count);
jsArray.Append("]='sonmenu");
jsArray.Append(menu.MenuId);
jsArray.Append("_top';");
count++;
}
menuString.Append("</tr></table>");
//加载子菜单
foreach (MenuEntity menu in menus)
{
List<MenuEntity> sonMenus = menuBl.QueryMenu(menu.MenuId);
if (sonMenus.Count > 0)
{
menuString.Append("<div id='sonmenu" + menu.MenuId + "_top' class='sonMenu_top'");
menuString.Append("style=' z-index:1;position:absolute;'");
menuString.Append(">");
menuString.Append("<ul>");
foreach (MenuEntity sonMenu in sonMenus)
{
menuString.Append("<li id='li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top' class='li_top' onmouseover='liOver_top(li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top)' onmouseout='liOut_top(li");
menuString.Append(sonMenu.MenuId);
menuString.Append("_top)' onclick=\"liClick_top('");
menuString.Append(sonMenu.PageUrl);
menuString.Append("','");
menuString.Append(Target);
menuString.Append("')\">");
menuString.Append(sonMenu.MenuName);
menuString.Append("</li>");
}
menuString.Append("</ul></div>");
}
}
jsArray.Append("</script>");
menuString.Append(jsArray.ToString());
this.divContain_top.InnerHtml = menuString.ToString();
}
}
3、topmenu.css
.parentMenu_top
{
background-color:#CCCCCC;
cursor:hand;
width:100px;
margin:0px 0px 0px 0px;
}
.parentMenuOver_top
{
background-color:#999999;
cursor:hand;
}
.parentMenuOut_top
{
background-color:#CCCCCC;
cursor:hand;
}
.sonMenu_top
{
display:none;
}
.sonMenuSel_top
{
background-color:#999999;
}
.view_top
{
display:inline-block;
}
.hidden_top
{
display:none;
}
.liOver_top
{
background-color:#E8E8E8;
}
.liOut_top
{
background-color:#F7F7F7;
}
li
{
background-color:#F7F7F7;
height:20px;
width:100px;
}
4、topmenu.js
//移动到父菜单时调用
function parentMenuOver_top(menuId)
{
var len=parentArray.length;
document.getElementById(menuId.id).className="parentMenuOver_top";
for( i=0;i<len;i++)
{
document.getElementById(parentArray[i].substring(3,parentArray[i].length)).className="parentMenuOut_top";
document.getElementById(parentArray[i]).className="hidden_top";
}
document.getElementById(menuId.id).className="parentMenuOver_top";
document.getElementById("son"+menuId.id).className="view_top";
}
//移出菜单1秒后自动关闭
var smId;
var hiddenTime;
function autoClose()
{
document.getElementById(smId.id.substring(3,smId.length)).className="parentMenuOut_top";
document.getElementById(smId.id).className="sonMenu_top";
}
//移出父菜单时调用
function parentMenuOut_top(menuId,sonMenuId)
{
//document.getElementById(menuId.id).className="parentMenuOut_top";
//document.getElementById(sonMenuId.id).className="sonMenu_top";
smId=sonMenuId;
if(hiddenTime!=null)
{
clearTimeout(hiddenTime);
}
hiddenTime=setTimeout("autoClose()",1000);
}
//移出子菜单时调用
function sonMenuOut_top(sonMenuId)
{
// document.getElementById(sonMenuId.id).className="sonMenu_top";
smId=sonMenuId;
if(hiddenTime!=null)
{
clearTimeout(hiddenTime);
}
hiddenTime=setTimeout("autoClose()",1000);
}
//移动到子菜单项时调用
function liOver_top(liId)
{
document.getElementById(liId.id).className="liOver_top";
}
//移出子菜单项时调用
function liOut_top(liId)
{
document.getElementById(liId.id).className="liOut_top";
}
//点击子菜单时调用
function liClick_top(pageUrl,target)
{
if(target!="_top"&&target!="_self"&&target!="_parent"&&target!="_blank")
{
eval(target).location.href=pageUrl;
}
}
//控件的加载事件,用于子菜单的位置
function load()
{
var len=parentArray.length;
for( i=0;i<len;i++)
{
var left=0;
var top=0;
//获取父菜单的位置
var obj=document.getElementById(parentArray[i].substring(3,parentArray[i].length));
left+=obj.offsetLeft;
top+=obj.offsetTop;
while(obj = obj.offsetParent){
left += obj.offsetLeft;
top +=obj.offsetTop;
}
document.getElementById(parentArray[i]).style.left=left;
document.getElementById(parentArray[i]).style.top=top+20;
}
}
//自动加载
window.onload=load;
2007年6月20日
2007年6月7日
一、适合读者对象:数据库开发程序员,数据库的数据量很多,涉及到对SP(存储过程)的优化的项目开发人员,对数据库有浓厚兴趣的人。
二、介绍:在数据库的开发过程中,经常会遇到复杂的业务逻辑和对数据库的操作,这个时候就会用SP来封装数据库操作。如果项目的SP较多,书写又没有一定的规范,将会影响以后的系统维护困难和大SP逻辑的难以理解,另外如果数据库的数据量大或者项目对SP的性能要求很,就会遇到优化的问题,否则速度有可能很慢,经过亲身经验,一个经过优化过的SP要比一个性能差的SP的效率甚至高几百倍。
三、内容:
1、开发人员如果用到其他库的Table或View,务必在当前库中建立View来实现跨库操作,最好不要直接使用“databse.dbo.table_name”,因为sp_depends不能显示出该SP所使用的跨库table或view,不方便校验。
2、开发人员在提交SP前,必须已经使用set showplan on分析过查询计划,做过自身的查询优化检查。
3、高程序运行效率,优化应用程序,在SP编写过程中应该注意以下几点:
a)SQL的使用规范:
i. 尽量避免大事务操作,慎用holdlock子句,提高系统并发能力。
ii. 尽量避免反复访问同一张或几张表,尤其是数据量较大的表,可以考虑先根据条件提取数据到临时表中,然后再做连接。
iii. 尽量避免使用游标,因为游标的效率较差,如果游标操作的数据超过1万行,那么就应该改写;如果使用了游标,就要尽量避免在游标循环中再进行表连接的操作。
iv. 注意where字句写法,必须考虑语句顺序,应该根据索引顺序、范围大小来确定条件子句的前后顺序,尽可能的让字段顺序与索引顺序相一致,范围从大到小。
v. 不要在where子句中的“=”左边进行函数、算术运算或其他表达式运算,否则系统将可能无法正确使用索引。
vi. 尽量使用exists代替select count(1)来判断是否存在记录,count函数只有在统计表中所有行数时使用,而且count(1)比count(*)更有效率。
vii. 尽量使用“>=”,不要使用“>”。
viii. 注意一些or子句和union子句之间的替换
ix. 注意表之间连接的数据类型,避免不同类型数据之间的连接。
x. 注意存储过程中参数和数据类型的关系。
xi. 注意insert、update操作的数据量,防止与其他应用冲突。如果数据量超过200个数据页面(400k),那么系统将会进行锁升级,页级锁会升级成表级锁。
b)索引的使用规范:
i. 索引的创建要与应用结合考虑,建议大的OLTP表不要超过6个索引。
ii. 尽可能的使用索引字段作为查询条件,尤其是聚簇索引,必要时可以通过index index_name来强制指定索引
iii. 避免对大表查询时进行table scan,必要时考虑新建索引。
iv. 在使用索引字段作为条件时,如果该索引是联合索引,那么必须使用到该索引中的第一个字段作为条件时才能保证系统使用该索引,否则该索引将不会被使用。
v. 要注意索引的维护,周期性重建索引,重新编译存储过程。
c)tempdb的使用规范:
i. 尽量避免使用distinct、order by、group by、having、join、cumpute,因为这些语句会加重tempdb的负担。
ii. 避免频繁创建和删除临时表,减少系统表资源的消耗。
iii. 在新建临时表时,如果一次性插入数据量很大,那么可以使用select into代替create table,避免log,提高速度;如果数据量不大,为了缓和系统表的资源,建议先create table,然后insert。
iv. 如果临时表的数据量较大,需要建立索引,那么应该将创建临时表和建立索引的过程放在单独一个子存储过程中,这样才能保证系统能够很好的使用到该临时表的索引。
v. 如果使用到了临时表,在存储过程的最后务必将所有的临时表显式删除,先truncate table,然后drop table,这样可以避免系统表的较长时间锁定。
vi. 慎用大的临时表与其他大表的连接查询和修改,减低系统表负担,因为这种操作会在一条语句中多次使用tempdb的系统表。
d)合理的算法使用:
根据上面已提到的SQL优化技术和ASE Tuning手册中的SQL优化内容,结合实际应用,采用多种算法进行比较,以获得消耗资源最少、效率最高的方法。具体可用ASE调优命令:set statistics io on, set statistics time on , set showplan on 等
2007年6月5日
2007年5月31日
2007年2月1日
http://www.aoxiang.org 2006-4-2 10:48:02 Unicode是一种字符编码规范 。
先从ASCII说起。ASCII是用来表示英文字符的一种编码规范,每个ASCII字符占用1个字节(8bits)
因此,ASCII编码可以表示的最大字符数是256,其实英文字符并没有那么多,一般只用前128个(最高位为0),其中包括了控制字符、数字、大小写字母和其他一些符号
。
而最高位为1的另128个字符被成为“扩展ASCII”,一般用来存放英文的制表符、部分音标字符等等的一些其他符号,这种字符编码规范显然用来处理英文没有什么问题。(实际上也可以用来处理法文、德文等一些其他的西欧字符,但是不能和英文通用),但是面对中文、阿拉伯文之类复杂的文字,255个字符显然不够用
于是,各个国家纷纷制定了自己的文字编码规范,其中中文的文字编码规范叫做“GB2312-80”,它是和ASCII兼容的一种编码规范,其实就是利用扩展ASCII没有真正标准化这一点,把一个中文字符用两个扩展ASCII字符来表示。
但是这个方法有问题,最大的问题就是,中文文字没有真正属于自己的编码,因为扩展ASCII码虽然没有真正的标准化,但是PC里的ASCII码还是有一个事实标准的(存放着英文制表符),所以很多软件利用这些符号来画表格。这样的软件用到中文系统中,这些表格符就会被误认作中文字,破坏版面。而且,统计中英文混合字符串中的字数,也是比较复杂的,我们必须判断一个ASCII码是否扩展,以及它的下一个ASCII是否扩展,然后才“猜”那可能是一个中文字
。
总之当时处理中文是很痛苦的。而更痛苦的是GB2312是国家标准,台湾当时有一个Big5编码标准,很多编码和GB是相同的,所以……,嘿嘿。
这时候,我们就知道,要真正解决中文问题,不能从扩展ASCII的角度入手,也不能仅靠中国一家来解决。而必须有一个全新的编码系统,这个系统要可以将中文、英文、法文、德文……等等所有的文字统一起来考虑,为每个文字都分配一个单独的编码,这样才不会有上面那种现象出现。
于是,Unicode诞生了。
Unicode有两套标准,一套叫UCS-2(Unicode-16),用2个字节为字符编码,另一套叫UCS-4(Unicode-32),用4个字节为字符编码。
以目前常用的UCS-2为例,它可以表示的字符数为2^16=65535,基本上可以容纳所有的欧美字符和绝大部分的亚洲字符
。
UTF-8的问题后面会提到 。
在Unicode里,所有的字符被一视同仁。汉字不再使用“两个扩展ASCII”,而是使用“1个Unicode”,注意,现在的汉字是“一个字符”了,于是,拆字、统计字数这些问题也就自然而然的解决了
。
但是,这个世界不是理想的,不可能在一夜之间所有的系统都使用Unicode来处理字符,所以Unicode在诞生之日,就必须考虑一个严峻的问题:和ASCII字符集之间的不兼容问题。
我们知道,ASCII字符是单个字节的,比如“A”的ASCII是65。而Unicode是双字节的,比如“A”的Unicode是0065,这就造成了一个非常大的问题:以前处理ASCII的那套机制不能被用来处理Unicode了
。
另一个更加严重的问题是,C语言使用'\0'作为字符串结尾,而Unicode里恰恰有很多字符都有一个字节为0,这样一来,C语言的字符串函数将无法正常处理Unicode,除非把世界上所有用C写的程序以及他们所用的函数库全部换掉
。
于是,比Unicode更伟大的东东诞生了,之所以说它更伟大是因为它让Unicode不再存在于纸上,而是真实的存在于我们大家的电脑中。那就是:UTF。
UTF= UCS Transformation Format UCS转换格式,它是将Unicode编码规则和计算机的实际编码对应起来的一个规则。现在流行的UTF有2种:UTF-8和UTF-16
。
其中UTF-16和上面提到的Unicode本身的编码规范是一致的,这里不多说了。而UTF-8不同,它定义了一种“区间规则”,这种规则可以和ASCII编码保持最大程度的兼容
。
UTF-8有点类似于Haffman编码,它将Unicode编码为00000000-0000007F的字符,用单个字节来表示;
00000080-000007FF的字符用两个字节表示
00000800-0000FFFF的字符用3字节表示
因为目前为止Unicode-16规范没有指定FFFF以上的字符,所以UTF-8最多是使用3个字节来表示一个字符。但理论上来说,UTF-8最多需要用6字节表示一个字符。
在UTF-8里,英文字符仍然跟ASCII编码一样,因此原先的函数库可以继续使用。而中文的编码范围是在0080-07FF之间,因此是2个字节表示(但这两个字节和GB编码的两个字节是不同的),用专门的Unicode处理类可以对UTF编码进行处理。
下面说说中文的问题。
由于历史的原因,在Unicode之前,一共存在过3套中文编码标准。
GB2312-80,是中国大陆使用的国家标准,其中一共编码了6763个常用简体汉字。Big5,是台湾使用的编码标准,编码了台湾使用的繁体汉字,大概有8千多个。HKSCS,是中国香港使用的编码标准,字体也是繁体,但跟Big5有所不同。
这3套编码标准都采用了两个扩展ASCII的方法,因此,几套编码互不兼容,而且编码区间也各有不同
因为其不兼容性,在同一个系统中同时显示GB和Big5基本上是不可能的。当时的南极星、RichWin等等软件,在自动识别中文编码、自动显示正确编码方面都做了很多努力。
他们用了怎样的技术我就不得而知了,我知道好像南极星曾经以同屏显示繁简中文为卖点。
后来,由于各方面的原因,国际上又制定了针对中文的统一字符集GBK和GB18030,其中GBK已经在Windows、Linux等多种操作系统中被实现。
GBK兼容GB2312,并增加了大量不常用汉字,还加入了几乎所有的Big5中的繁体汉字。但是GBK中的繁体汉字和Big5中的几乎不兼容。
GB18030相当于是GBK的超集,比GBK包含的字符更多。据我所知目前还没有操作系统直接支持GB18030。
谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词
这是一篇程序员写给程序员的趣味读物。所谓趣味是指可以比较轻松地了解一些原来不清楚的概念,增进知识,类似于打RPG游戏的升级。整理这篇文章的动机是两个问题:
问题一:
使用Windows记事本的“另存为”,可以在GBK、Unicode、Unicode big
endian和UTF-8这几种编码方式间相互转换。同样是txt文件,Windows是怎样识别编码方式的呢?
我很早前就发现Unicode、Unicode big endian和UTF-8编码的txt文件的开头会多出几个字节,分别是FF、FE(Unicode),FE、FF(Unicode big endian),EF、BB、BF(UTF-8)。但这些标记是基于什么标准呢?
问题