用户登陆
站点日历
7 3 2009 - 9 4 8 日 一 二 三 四 五 六 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
站点公告
Goldtimes.net全面改版中...
本站今后将以原创文章、教程为主,谢谢大家的支持,大家还有什么好的建议或意见,都可以在这里提出!
站长简介:
Agang,生于八十年代.多年媒体及互联网从业经验,关注互联网、电子商务和网络技术.中国商贸网(tradevnet.cn)创办人
blog.goldtimes.net
国内唯一专注于web2.0源码收藏,分享的技术blog
站点统计
联系方式
手机:
13686861114 QQ:
993715476 Email:anyshop@126.com
日志搜索
友情链接
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... [11] 通常,在执行多条sql语句时,我们会采用下面的方法:
<% sql1 = "update table1 set a=b where id=1" conn.execute sql1 sql2 = "update table2 set a=b where id=2" conn.execute sql2 sql3 = "update table3 set a=b where id=3" conn.execute sql3 %>
事实上,这是一种效率很低下的写法,为了提高sql的执行效率,我们可以把多个sql语句用分号拼接在一起,然后一次性交给conn来执行。如下:
<% sql1 = "update table1 set a=b where id=1" sql2 = "update table2 set a=b where id=2" sql3 = "update table3 set a=b where id=3" sql = sql1 & ";" & sql2 & ";" & sql3 conn.execute sql %>
但是,以上2种写法都会面临一个问题,就是当我们需要保证3条sql语句都必须完整执行,当某一条执行错误时,其他2条也跟着回滚时,我们就需要用到sqlserver的事务控制了,不少的文章建议使用以下方法:
<% dim conn=server.createobject("adodb.connection") '开始事务 conn.begintrans '执行sql,若成功则提交事,否则回滚事务 conn.execute(sql语句) '提交事务 conn.committrans '回滚事务 conn.rollbacktrans %>
在很多时候,这并不能达到保证sql语句完整执行的目的,高效的做法应该是利用sqlserver本身的事务控制功能,如下:
<% sub exesql(byval sqlstr) dim trsql trsql = "set xact_abort on;begin transaction;" trsql = trsql & sqlstr trsql = trsql & ";commit transaction;set xact_abort off" conn.execute(trsql) end sub
sql1 = "update table1 set a=b where id=1" sql2 = "update table2 set a=b where id=2" sql3 = "update table3 set a=b where id=3" sql = sql1 & ";" & sql2 & ";" & sql3 exesql sql %>
本篇文章来源于 goldtimes.net 原文链接:http://www.goldtimes.net/goldtimes/view.asp?id=657
create trigger tr_deletecompany on company for delete as delete info from info a join deleted b on a.username=b.username go
删除企业表,同时删除该企业发布的信息
-----------------------------------------------------------
create trigger tr_deletecompany2 on company for delete as delete classified from classified a join deleted b on a.username=b.username go
-----------------------------------------------------------
delete from company where companyname='' or companyname is null
sql> delete news;
已删除2行。
sql> drop table news;
表已删除。
sql> create table news( 2 id varchar2(20) not null, 3 objid varchar2(20) not null, 4 title varchar2(60) not null, 5 author varchar2(40), 6 fromwhere varchar2(60), 7 content clob, 8 adddate date, 9 constraint pk_news primary key(id), 10 constraint fk_news foreign key(objid) 11 references newobj(id) 12 on delete cascade);
表已创建。
sql> insert into news(id,objid,title)values('10','10','buy the computer');
已创建 1 行。
sql> insert into news(id,objid,title)values('20','10','i love you');
已创建 1 行。
sql> select count(*) from newobj;
count(*) ---------- 2
sql> select count(*) from news;
count(*) ---------- 2
sql> delete from newobj where id='10';
已删除 1 行。
sql> select count(*) from newobj;
count(*) ---------- 1
sql> select count(*) from news;
count(*) ---------- 0
我删除新闻表,然后重建新闻表,并加了:on delete cascade
添加相应记录,我试着删除新闻栏目id为10的栏目;新闻表中的记录也跟着删除了;
小结: on delete cascade实现了级联删除;
asp高级编程:大型数据库建表技术
'建立数据库 sql="create table [db_posts"&request("tablename")&"] ("&_ "id int identity (1, 1) not null ,"&_ "threadid int not null ,"&_ "istopic int default 0 not null ,"&_ "subject varchar(255) not null ,"&_ "username varchar(255) not null ,"&_ "content text not null ,"&_ "posttime datetime default "&sqlnowstring&" not null ,"&_ "postip varchar(255) not null "&_ ")" conn.execute(sql)
'建立关联 sql="alter table [db_posts"&request("tablename")&"] add constraint [fk_db_posts"&request("tablename")&"_db_threads] foreign key ([threadid]) references [db_threads] ([id]) on delete cascade on update cascade" conn.execute(sql)
error("建立成功!")
----------------------------
--在自己创建的数据库中创建表
use sb --使用某个数据库,格式: ues 数据库名 create table 123 --格式:create table 自定义的表名 ( --字段名一般为有一定意义的英文 names char (15), -- 格式:字段名 类型 () 括号里面的是允许输入的长度 age int, --int型的后面不要接长度 years text (20) --最后一个字段后面不要逗号 )
--在创建表时就可以对字段加上约束: create table 123 ( names char (15) primary key identity(1,1) , --加主键约束,还有标识列属性(两者构成实体完整性) age int not null, --加非空约束,不打"not null"默认为:可以为空 years text (20) foreign key references 456(years), --加外键约束,格式:foreign key references 关联的表名(字段名) class char (20) default '哈哈' --加默认值约束 school char (30) check(school='十五' or school='十') --加检查约束,格式:check (条件表达式) -- )
--如果在表创建好了以后再加约束,则格式分别为:
-- 主键: alter table 表名 add constraint pk_字段名 --"pk"为主键的缩写,字段名为要在其上创建主键的字段名,'pk_字段名'就为约束名 primary key (字段名) --字段名同上
--唯一约束: alter table 表名 add constraint uq_字段名 unique (字段名)
--外键约束: alter table 表名 add constraint fk_字段名 --"fk"为外键的缩写 foreign key 字段名 references 关联的表名 (关联的字段名) --注意'关联的表名'和'关联的字段名'
--检查约束: alter table 表名 add constraint ck_字段名 check (条件表达式) --条件表达式中的条件用关系运算符连接
--默认值约束: alter table 表名 add constraint df_字段名 default '默认值' for 字段名 --其中的'默认值'为你想要默认的值,注意'for'
--删除创建的约束: alter table 表名 drop constraint 约束名 --约束名为你前面创建的如:pk_字段 这样的约束名 --注意:如果约束是在创建表的时候创建的,则不能用命令删除 --只能在'企业管理器'里面删除
服务器上打开任务管理器的方法 [ 2009-07-11 |
本站原创 ]
怎么样打开任务管理
方法一:在"运行"里输入taskmgr
方法二:在任务栏击右键
右键点击下方的启动工具栏或者时间,选择“任务管理器”
php获取qq邮箱用户好友的方法 [ 2009-07-11 |
转载 ]
我用php做了改写,可能有不完善的地方。
附件中有代码,
主要的类为class.qqhttp.php
php代码 <?php /** * @file class.qqhttp.php * qq邮箱登陆获取类 * @author wc<cao8222@gmail.com > * @date 2009-04-27 */ class qqhttp { var $cookie = ''; function __cunstrut() { } function makeform() { $form = array( 'url' => "http://mail.qq.com/cgi-bin/loginpage ", ); $data = $this->curlfunc($form); preg_match('/name="ts"\svalue="(\d+)"/',$data['html'], $tspre); $ts = $tspre[1]; preg_match('/action="http:\/\/(m\d+)\.mail\.qq\.com/',$data['html'], $server); $server_no = $server[1]; /* login.html 载入 */ $html = file_get_contents(dirname(__file__).'/login.htm'); $html = str_replace('{_ts_}',$ts, $html); $html = str_replace('{_server_no_}',$server_no, $html); return $html; } function curlfunc($array) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $array['url']); curl_setopt($ch, curlopt_returntransfer, true); if( isset($array['header']) && $array['header'] ) { curl_setopt($ch, curlopt_header, 1); } if(isset($array['httpheader'])) { curl_setopt($ch, curlopt_httpheader, $array['httpheader']); } if(isset($array['referer'])) { curl_setopt($ch, curlopt_referer, $array['referer']); } if( isset($array['post']) ) { curl_setopt($ch, curlopt_post, 1 ); curl_setopt($ch, curlopt_postfields, $array['post']); } if( isset($array['cookie']) ){ curl_setopt($ch, curlopt_cookie, $array['cookie']); } $r['erro'] = curl_error($ch); $r['errno'] = curl_errno($ch); $r['html'] = curl_exec($ch); $r['http_code'] = curl_getinfo($ch, curlinfo_http_code); curl_close($ch); return $r; } /** * 获取验证码图片和cookie * @param null * * @return array('img'=>string, 'cookie'=>string) */ function getvfcode () { $vfcode = array( 'header' => true, 'cookie' => false, 'url'=>'http://ptlogin2.qq.com/getimage?aid='.$_get['aid'].'&'.@$_get['t'], ); $r = $this->curlfunc($vfcode); if ($r['http_code'] != 200 ) return false; $data = split("\n", $r['html']); preg_match('/verifysession=([^;]+);/',$data[5], $temp); $cookie = trim($temp[1]); $img = $data[9]; return array('img'=>$img,'cookie'=>$cookie); } /** * 登陆qq邮箱 * * @param $cookie getvfcode中生成的cookie * * @return array( * sid=>string , //用户认证的唯一标示 * login => boolean, //true 登陆成功 ,false 登陆失败 * server_no => string // 服务器编号 * active => boolean //true 已开通 ,false 未开通 邮箱 * cookie => string // 获取数据cookie * * ); */ function login($cookie) { /* 生成参数字符串 */ $post = array(); foreach($_post as $k => $v) { $post[] = $k.'='.urlencode($v); } $poststr = implode('&',$post); $r['server_no'] = $_get['server_no']; $login = array( 'url'=>'http://'.$r['server_no'].'.mail.qq.com/cgi-bin/login?sid=0,2,zh_cn', 'header' => true, 'cookie' => 'verifysession='.$cookie, 'referer' => 'http://mail.qq.com/cgi-bin/loginpage', 'httpheader'=>array( "host: " . $r['server_no'] . '.mail.qq.com', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", "content-type: application/x-www-form-urlencoded", ), 'post' => $poststr , ); $data = $this->curlfunc($login); $data['html'] = iconv("gb2312", "utf-8", $data['html']); if ($data['http_code'] != 200) { $this->error($data); return false; } /* 测试数据 */ //$data['html'] =file_get_contents('./r.txt'); $r['uin'] = $_post['uin']; /* 登陆错误的判断 */ if (preg_match('|errtype=(\d)|', $data['html'], $temp_err)) { $r['login'] = false; if ($temp_err[1] == 1) { $r['msg'] = '账号和密码错误'; } elseif ($temp_err[1] == 2) { $r['msg'] = '验证码错误'; } return $r; } /* 登陆成功 */ preg_match('|urlhead="([^"]+)"|i',$data['html'],$temp_url); $urlhead = $temp_url[1]; if (preg_match('|frame_html\?sid=([^"]+)"|i',$data['html'],$temp_sid) ) { $r['sid'] = $temp_sid[1]; $r['active'] = true; } elseif (preg_match('|autoactivation\?sid=([^&]+)?&|i',$data['html'],$temp_sid) ) { $r['sid'] = $temp_sid[1]; $r['active'] = false; } /* 登录后cookie的获取 ,在后续操作中用到 */ if (preg_match_all('|set-cookie:([^=]+=[^;]+)|i', $data['html'], $new_cookies) ) { $cookiestr = implode('; ', $new_cookies[1]); $cookiestr .= '; verifysession='.$cookie; } $r['login'] = true; $r['cookie'] = $cookiestr; return $r; } function openemail($param) { $openemail = array( 'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/autoactivation?actmode=6&sid='.$param['sid'], 'header' => true, 'cookie' => $param['cookie'], 'referer' => 'http://'.$param['server_no'].'mail.qq.com/cgi-bin/autoactivation?sid='.$param['sid'].'&action=reg_activate&actmode=6', 'httpheader'=>array( "host: " . $param['server_no'] . '.mail.qq.com', 'accept-charset: gb2312,utf-8;q=0.7,*;q=0.7', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", ), ); $data = $this->curlfunc($openemail); if (preg_match('|set-cookie:qqmail_activated=0|i', $data['html'])) { $param['active'] = true; $param['cookie'] = $param['cookie'] .'; qqmail_activated=0; qqmail_alias='; } return $param; } /** * * 获取friends数据 * * @param $param = array( * sid=>string , //用户认证的唯一标示 * login => boolean, //true 登陆成功 ,false 登陆失败 * server_no => string // 服务器编号 * active => boolean //true 已开通 ,false 未开通 邮箱 * cookie => string // 获取数据cookie * * ); * @return array( * key=>value, // key:qq号,value: nickname * ); */ function getfriends($param) { $friend = array( 'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/addr_listall?type=user&&category=all&sid='.$param['sid'], 'header' => true, 'cookie' => $param['cookie'], 'referer' => 'http://m151.mail.qq.com/cgi-bin/addr_listall?sid='.$param['sid'].'&sorttype=null&category=common', 'httpheader'=>array( "host: " . $param['server_no'] . '.mail.qq.com', 'accept-charset:utf-8;q=0.7,*;q=0.7', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", ), ); $r = $this->curlfunc($friend); if ($r['http_code'] != 200) { $this->error($r); return false; } $data = $r['html']; $preg = preg_match_all('|<p class="l_n"><span><img class="l_q" name=qqplusimg key="(\d+)"[^>]+/> ([^<]+)</span></p>|i', $data, $temp_list); if ($preg == 0) return array(); $list = array_combine($temp_list[1],$temp_list[2]); return $list; } /** * 错误显示 * * @param $str array * * @return */ function error($str) { $str['html'] = str_replace('script','', $str['html']); var_dump($str); exit; } } ?>
<?php /** * @file class.qqhttp.php * qq邮箱登陆获取类 * @author wc<cao8222@gmail.com > * @date 2009-04-27 */
class qqhttp {
var $cookie = '';
function __cunstrut() { }
function makeform() { $form = array( 'url' => "http://mail.qq.com/cgi-bin/loginpage ", ); $data = $this->curlfunc($form); preg_match('/name="ts"\svalue="(\d+)"/',$data['html'], $tspre); $ts = $tspre[1]; preg_match('/action="http:\/\/(m\d+)\.mail\.qq\.com/',$data['html'], $server); $server_no = $server[1];
/* login.html 载入 */ $html = file_get_contents(dirname(__file__).'/login.htm'); $html = str_replace('{_ts_}',$ts, $html); $html = str_replace('{_server_no_}',$server_no, $html); return $html; }
function curlfunc($array) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $array['url']); curl_setopt($ch, curlopt_returntransfer, true); if( isset($array['header']) && $array['header'] ) { curl_setopt($ch, curlopt_header, 1); } if(isset($array['httpheader'])) { curl_setopt($ch, curlopt_httpheader, $array['httpheader']); } if(isset($array['referer'])) { curl_setopt($ch, curlopt_referer, $array['referer']); } if( isset($array['post']) ) { curl_setopt($ch, curlopt_post, 1 ); curl_setopt($ch, curlopt_postfields, $array['post']); } if( isset($array['cookie']) ){ curl_setopt($ch, curlopt_cookie, $array['cookie']); } $r['erro'] = curl_error($ch); $r['errno'] = curl_errno($ch); $r['html'] = curl_exec($ch); $r['http_code'] = curl_getinfo($ch, curlinfo_http_code); curl_close($ch); return $r; }
/** * 获取验证码图片和cookie * @param null * * @return array('img'=>string, 'cookie'=>string) */ function getvfcode () { $vfcode = array( 'header' => true, 'cookie' => false, 'url'=>'http://ptlogin2.qq.com/getimage?aid='.$_get['aid'].'&'.@$_get['t'], );
$r = $this->curlfunc($vfcode); if ($r['http_code'] != 200 ) return false; $data = split("\n", $r['html']); preg_match('/verifysession=([^;]+);/',$data[5], $temp); $cookie = trim($temp[1]); $img = $data[9]; return array('img'=>$img,'cookie'=>$cookie); }
/** * 登陆qq邮箱 * * @param $cookie getvfcode中生成的cookie * * @return array( * sid=>string , //用户认证的唯一标示 * login => boolean, //true 登陆成功 ,false 登陆失败 * server_no => string // 服务器编号 * active => boolean //true 已开通 ,false 未开通 邮箱 * cookie => string // 获取数据cookie * * ); */ function login($cookie) { /* 生成参数字符串 */ $post = array(); foreach($_post as $k => $v) { $post[] = $k.'='.urlencode($v); } $poststr = implode('&',$post); $r['server_no'] = $_get['server_no'];
$login = array( 'url'=>'http://'.$r['server_no'].'.mail.qq.com/cgi-bin/login?sid=0,2,zh_cn', 'header' => true, 'cookie' => 'verifysession='.$cookie, 'referer' => 'http://mail.qq.com/cgi-bin/loginpage', 'httpheader'=>array( "host: " . $r['server_no'] . '.mail.qq.com', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", "content-type: application/x-www-form-urlencoded", ), 'post' => $poststr , ); $data = $this->curlfunc($login); $data['html'] = iconv("gb2312", "utf-8", $data['html']); if ($data['http_code'] != 200) { $this->error($data); return false; }
/* 测试数据 */ //$data['html'] =file_get_contents('./r.txt'); $r['uin'] = $_post['uin']; /* 登陆错误的判断 */ if (preg_match('|errtype=(\d)|', $data['html'], $temp_err)) { $r['login'] = false; if ($temp_err[1] == 1) { $r['msg'] = '账号和密码错误'; } elseif ($temp_err[1] == 2) { $r['msg'] = '验证码错误'; } return $r; } /* 登陆成功 */ preg_match('|urlhead="([^"]+)"|i',$data['html'],$temp_url); $urlhead = $temp_url[1]; if (preg_match('|frame_html\?sid=([^"]+)"|i',$data['html'],$temp_sid) ) { $r['sid'] = $temp_sid[1]; $r['active'] = true; } elseif (preg_match('|autoactivation\?sid=([^&]+)?&|i',$data['html'],$temp_sid) ) { $r['sid'] = $temp_sid[1]; $r['active'] = false; } /* 登录后cookie的获取 ,在后续操作中用到 */ if (preg_match_all('|set-cookie:([^=]+=[^;]+)|i', $data['html'], $new_cookies) ) { $cookiestr = implode('; ', $new_cookies[1]); $cookiestr .= '; verifysession='.$cookie; }
$r['login'] = true; $r['cookie'] = $cookiestr; return $r; }
function openemail($param) { $openemail = array( 'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/autoactivation?actmode=6&sid='.$param['sid'], 'header' => true, 'cookie' => $param['cookie'], 'referer' => 'http://'.$param['server_no'].'mail.qq.com/cgi-bin/autoactivation?sid='.$param['sid'].'&action=reg_activate&actmode=6', 'httpheader'=>array( "host: " . $param['server_no'] . '.mail.qq.com', 'accept-charset: gb2312,utf-8;q=0.7,*;q=0.7', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", ), );
$data = $this->curlfunc($openemail); if (preg_match('|set-cookie:qqmail_activated=0|i', $data['html'])) { $param['active'] = true; $param['cookie'] = $param['cookie'] .'; qqmail_activated=0; qqmail_alias='; } return $param; }
/** * * 获取friends数据 * * @param $param = array( * sid=>string , //用户认证的唯一标示 * login => boolean, //true 登陆成功 ,false 登陆失败 * server_no => string // 服务器编号 * active => boolean //true 已开通 ,false 未开通 邮箱 * cookie => string // 获取数据cookie * * ); * @return array( * key=>value, // key:qq号,value: nickname * ); */ function getfriends($param) {
$friend = array( 'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/addr_listall?type=user&&category=all&sid='.$param['sid'], 'header' => true, 'cookie' => $param['cookie'], 'referer' => 'http://m151.mail.qq.com/cgi-bin/addr_listall?sid='.$param['sid'].'&sorttype=null&category=common', 'httpheader'=>array( "host: " . $param['server_no'] . '.mail.qq.com', 'accept-charset:utf-8;q=0.7,*;q=0.7', "user-agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4", ), ); $r = $this->curlfunc($friend); if ($r['http_code'] != 200) { $this->error($r); return false; } $data = $r['html']; $preg = preg_match_all('|<p class="l_n"><span><img class="l_q" name=qqplusimg key="(\d+)"[^>]+/> ([^<]+)</span></p>|i', $data, $temp_list); if ($preg == 0) return array(); $list = array_combine($temp_list[1],$temp_list[2]); return $list; }
/** * 错误显示 * * @param $str array * * @return */ function error($str) { $str['html'] = str_replace('script','', $str['html']); var_dump($str); exit; } }
?> qq_mail.rar
MYSQL每日一用:存储过程 [ 2009-07-11 |
转载 ]
今天要做一个统计报表,想到使用存储过程来做。
mysql的存储过程以前没有用过,这次想试试,在编写的过程中遇到了不少问题:
首先,看了官方的文档 ,不过对于存储过程,还是要使用才知道。文档是死的,人是活的。
1.怎么创建存储过程,自然也是使用一定语法,然后运行,如果成功,会有一个对应的文
件产生,并可以通过 call 来调用。
2.设定变量要注意,不是全局变量(@)时,要先定义(declare year_months varchar(10))
3.设置变量时的语法,在变量前面加 set 关键字,不然报错
4.直接执行sql,是可以的,但是如果我们的sql是动态的,比如我们表名是通过参数传进来的。
这时间要另外一种方式了,要将sql,使用concat(,,,),来讲sql连接起来。还有就是字符串拼接时,
最好使用concat(见下面的)函数,不然会有问题。
下面是我写的一个实例:
drop procedure if exists `crm_sms_stat`;
create definer=`boss`@`% ` procedure `crm_sms_stat`(in years varchar(10),in m varchar(10),in last_months varchar(10)) begin declare year_months varchar(10); declare year_m varchar(10); declare mt_sms_yearmonth varchar(20); declare r_year_month varchar(20); declare last_r_year_month varchar(20); set year_months = concat(years,m); set year_m = concat(years,'-',m); set mt_sms_yearmonth = concat("mt_sms_",year_months); set r_year_month = concat(years,"_",m); if m = "01" then set years = years - 1; set last_months = "12"; end if; set last_r_year_month = concat(years,"_",last_months); if years = "2008" then set r_year_month = concat("r",r_year_month); set last_r_year_month = concat("r",last_r_year_month); end if; /*---------------------------------------------------------------- */ set @insertstat = concat(' insert into crm_sms_stat(months,user_id,username,agentid) ', ' select "',year_months,'",u.user_id,u.username,u.agentid from ',mt_sms_yearmonth, ' mt inner join users u on mt.user_id=u.user_id group by mt.user_id '); prepare inserts from @insertstat; execute inserts; set @tempupdateremain = concat(' update crm_monthremain cm,crm_sms_stat css set css.last_remain = ifnull(', last_r_year_month,',0),css.this_remain = ifnull(', r_year_month,',0) ', ' where cm.id = css.user_id and css.months = "',year_months,'" '); prepare remain from @tempupdateremain; execute remain; -- 更新每个月用户所冲条数 set @tempadd = concat(' update crm_sms_stat css inner join (select name,sum(total_count) addnum from boss_addmoney ', ' where left(add_date,7)= "',year_m,'" and total_count >=0 and name not like "%=%" and name not like "%:%" group by name) ', ' x on css.username= x.name and css.months = "',year_months ,'" ', ' set css.add_num = ifnull(x.addnum,0) '); prepare addnum from @tempadd; execute addnum; if years = "08" then -- 更新通道发送数(200901之前是不分卡发和通道的) set @tempchannel08 = concat('update crm_sms_stat css inner join (select mt.user_id,', ' sum(length(replace(mt.dest_mobile,";","")))/11 chennel_num', ' from ',mt_sms_yearmonth,' mt ', ' group by mt.user_id) x on css.user_id = x.user_id and css.months = "',year_months,'"', ' set css.channel_num = ifnull(x.chennel_num,0) '); prepare channel08 from @tempchannel08; execute channel08; else -- channel send number set @tempchannel = concat('update crm_sms_stat css inner join (select mt.user_id,', ' sum(length(replace(mt.dest_mobile,";","")))/11 chennel_num', ' from ',mt_sms_yearmonth,' mt where mt.channel_id != 312 ', ' group by mt.user_id) x on css.user_id = x.user_id and css.months = "',year_months,'"', ' set css.channel_num = ifnull(x.chennel_num,0) '); prepare channel from @tempchannel; execute channel; -- card send number set @tempcard = concat('update crm_sms_stat css inner join (select mt.user_id,', ' sum(substring_index(substring_index(mt.dest_mobile, "real", 1),":",-1)) as submit_card_num,', ' sum(substring_index(mt.dest_mobile,":",-1)) as real_card_num', ' from ',mt_sms_yearmonth,' mt where mt.channel_id = 312 ', ' group by mt.user_id) x on css.user_id = x.user_id and css.months = "',year_months,'"', ' set css.submit_card_num = ifnull(x.submit_card_num,0),css.real_card_num = ifnull(x.real_card_num,0) '); prepare card from @tempcard; execute card; end if; end;
打开操作系统启动时pae
配置项; 步骤:找到系统安装的引导位置的目录下找到boot.ini文件,默认是隐藏只读的,找到 windows2003 启动配置,在后面加上空格 /pae ,保存;重启 示例所示: multi(0)disk(0)rdisk(0)partition(2)\%systemroot%= "windows server 2003 datacenter edition " /pae
4.1. 在windows server 2003使用sql server 2005概述 sql server 2005 支持在 windows server 2003 上动态分配 awe 映射内存。通过允许访问超过在所配置虚拟内存地址空间上设置的限制的可用物理内存,awe 可扩展 32 位操作系统上运行的应用程序的功能。
启动过程中,sql server 仅保留一小部分 awe 映射内存。需要额外的 awe 映射内存时,操作系统会动态地将其分配给 sql server。同样,如果需要更少的资源,sql server 会将 awe 映射内存返还给操作系统,以供其他进程或应用程序使用。sql server 和操作系统之间的这种平衡受到 min server memory 和 max server memory 参数的限制。
在 windows server 2003 中运行 sql server 2005 时,无需重新启动 sql server 实例,sql server 即可响应 max server memory 和 min server memory 配置选项的更改。
在 windows server 2003 下,如果服务器的物理内存小于虚拟内存地址空间上已配置的限制,则该服务器支持动态 awe 映射内存。在这种情况下使用 awe 不会对性能产生影响,但添加的物理内存超过虚拟内存地址限制时,可以在不重新启动服务器的情况下使用此物理内存。
4.2. 启用awe 对于 windows server 2003,由于 awe 映射内存管理是动态的,因此在启动过程中,只分配总可用物理内存的一小部分。
如果已成功启用此选项,当 sql server 2005 实例启动时,sql server 错误日志中将写入消息“address windowing extensions enabled”。
必须在启用 awe 之前为 sql server 帐户授予 lock page in memory 权限。
awe enabled 选项是一个高级选项。如果使用 sp_configure 系统存储过程来更改该设置,则只有在 show advanced options 设置为 1 时才能更改 awe enabled。必须重新启动 sql server 实例,awe 才会生效。
4.3. 启用锁定内存页选项(windows) 启用锁定内存页选项
在"开始"菜单上单击"运行"子菜单,然后在"打开"框中键入"gpedit.msc"。
在"组策略"控制台上,展开"计算机配置",然后展开"windows 设置"。
展开"安全设置",然后展开"本地策略"。
选择"用户权限分配"复选框。
详细资料窗格中随即显示出策略。
在详细资料窗格中,双击"锁定内存页"。
在"本地安全策略设置"对话框中,单击"添加"按钮。
在"选择用户或组"对话框中,添加有权运行 sqlservr.exe 的帐户。
4.4. 启用sql server 2005的awe支持 若要启用 awe,请将 awe enabled 设置为 1。除非指定了 max server memory 的值,否则 sql server 将保留几乎所有可用内存,只留下 128 mb 或更少。
如果已成功启用该选项,则当 sql server 2000 实例启动时,sql server 错误日志中将出现"已启用地址窗口扩展"这条消息。
awe enabled 是高级选项。如果正在使用 sp_configure 系统存储过程更改该设置,则只有
当 show advanced options 设置为 1 时才能更改 awe enabled。
如下:设定sql 使用6g的内存
sp_configure 'show advanced options', 1
reconfigure
go
sp_configure 'awe enabled', 1
reconfigure
go
sp_configure 'max server memory', 6144
reconfigure
go
4.5. 重新启动服务 必须重新启动 sql server 2005 实例才能使更改生效。
net stop mssqlserver
net start mssqlserver
这样,sql 服务启动后,就会把6g的内存给锁定,完全供sql使用
最后进行服务优化:
sc config mssqlserveradhelper start= disabled
sc config mssqlserverolapservice start= disabled
sc config sqlbrowser start= disabled
sc config msdtsserver start= disabled
net stop mssqlserveradhelper
net stop mssqlserverolapservice
net stop sqlbrowser
net stop msdtsserver
sp_who active --看看哪个引起的阻塞, blk sp_lock --看看锁住了那个资源id, objid , select object_name(objid) 得到 dbcc inputbuffer(@blk) -- 看看是那个语句
----------------------------------------------------------------------------
优化sqlserver的配置.sql
%% ******************************************************************************************************/ go
exec sp_configure "awe enabled","1"--内存可以支持64g exec sp_configure "lightweight pooling","0"--不使用nt纤程 exec sp_configure "priority boost","1"--增加sqlserver优先级 exec sp_configure "network packet size (b)","8192"--增加sqlserver网络包的大小
reconfigure with override
go
--优化数据库设置 declare @currentdatabase sysname select @currentdatabase = db_name((select dbid from master.dbo.sysprocesses where spid = @@spid))
exec sp_dboption @currentdatabase, "select into/bulkcopy", "true" --对大容量数据操作不记录日志 exec sp_dboption @currentdatabase, "trunc. log on chkpt.", "true" --自动截断日志 exec sp_dboption @currentdatabase, "auto create statistics", "true"--自动创建统计 exec sp_dboption @currentdatabase, "auto update statistics", "true"--自动更新统
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... [11]