• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
鱼要的是海洋,鸟要的是天空,我要的是自由!
平凡的人不平凡的人生
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  数据库应用实例

1 2 3 下一页
根据当月数据库自动生成下个月数据库--2

摘要:--方法2. 脚本复制use mastergo if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_ProcCopyDb]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[sp_ProcCopyDb]GO /*--数据库... 阅读全文
posted @ 2007-06-29 16:54 伊凡 阅读(430) 评论(0) 推荐(0)
根据当月数据库自动生成下个月数据库--3

摘要:--创建一个每月最后一个工作日执行的作业,调用上述存储过程实现自动创建数据库 use mastergo --设置 SQL Agent 服务为自动启动exec msdb..sp_set_sqlagent_properties @auto_start=1go --创建作业exec msdb..sp_add_job @job_name=N'自动建库处理' --创建作业步骤declare @sql var... 阅读全文
posted @ 2007-06-29 16:53 伊凡 阅读(283) 评论(0) 推荐(0)
在有限多的不大于100的正整数中,找出尽量多个相加起来值介于98~102之间的组合

摘要:问题描述: 在有限多的不大于100的正整数中,找出尽量多个相加起来值介于98~102之间的组合。 组合的个数限制在2 和3。 比如有数字(39,40,1,55,17,17……N)数字可以有重复。 找出的组合有(50,50),(21,41,39),(48,50)……M。在上面的数字在组合中每次只能出现一次(比如数字中40只出现过一次,那在组合中也只能出现一次。17出现过两次那在组合中最多两次) ... 阅读全文
posted @ 2007-06-29 16:52 伊凡 阅读(387) 评论(0) 推荐(0)
实现删除主表数据时, 判断与之关联的外键表是否有数据引用, 有标志, 无则删除

摘要:问题描述: 某个基础信息表,与系统中30多个表存在外键关系,当删除基础数据时,需要判断是否已经被用过,如果用过则更改标志位,如果没有用过则直接删除,如何能很好实现这个处理?最好能够自动适应表的变化 问题解决(SQL Server 2005) -- SQL Server 2005的错误处理容易控制, 因此, SQL Server 2005中可以直接删除, 通过错误处理来确定是否需要更新. ... 阅读全文
posted @ 2007-06-29 16:52 伊凡 阅读(958) 评论(0) 推荐(0)
使用事务与锁,实现一个用户取过的数据不被其他用户取到

摘要:问题描述: 用ADO访问数据库,从一个表中取一定的记录(比如20行),取出后在程序中使用,使用完后删除掉记录(不用更新或删除记录)。在多用户操作下(每个用户采用相同的操作),怎么保证一个用户已选取的记录不被其他用户选取? 问题解决: 处理这类问题的一般方法是增加一个标志列,每个用户取的记录设置一个标志,新的用户只从标志为未取的记录中获取记录。 而本文利用事务与锁来控制数据的处理,不需要增... 阅读全文
posted @ 2007-06-29 16:51 伊凡 阅读(406) 评论(0) 推荐(0)
如何快速生成100万不重复的8位编号

摘要:最近在论坛看到有人问,如何快速生成100万不重复的8位编号,对于这个问题,有几点是需要注意的: 1. 如何生成8位随机数,生成的数越随机,重复的可能性当然越小 2. 控制不重复 3. 考虑性能 针对这个问题,我写了如下的示例来解决,希望能为有这类需求的人提供指导 生成100万条8位不重复数据的示例 USE tempdb GO -- 创建测试表 CREATE TABLE... 阅读全文
posted @ 2007-06-29 16:51 伊凡 阅读(512) 评论(0) 推荐(0)
如何实现横向聚合

摘要:问题描述: 有表tb,数据如下 A1 A2 A3 A4 A5 1 2 5 3 4 2 2 3 4 5 0 3 4 2 5 如何输出 A1 A2 A3 A4 A5 最大 最小 5以上个数 1 2 5 3 4 5 1 1 2 2 3 4 5 5 2 1 0 3 5 2 6 6 0 ... 阅读全文
posted @ 2007-06-29 16:50 伊凡 阅读(337) 评论(0) 推荐(0)
根据排序定义表排序数据

摘要:根据排序定义表排序数据 测试数据:create table tb1(id int,col1 varchar(10),col2 int)insert tb1 select 1,'aa',111union all select 2,'aa',111union all select 3,'aa',111union all select 4,'bb',222union all select 5,... 阅读全文
posted @ 2007-06-29 16:49 伊凡 阅读(298) 评论(0) 推荐(0)
报表统计

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3826/3826130.xml?temp=.4175836--*/ --示例数据--建企业名称表CREATE TABLE qiye (qiyemingcheng char(16),xingzhi char(4),shunxu int)insert into qiye select '企业甲','国有'... 阅读全文
posted @ 2007-06-29 16:48 伊凡 阅读(376) 评论(0) 推荐(0)
根据当月数据库自动生成下个月数据库--1

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3818/3818559.xml?temp=.9593317--*/ /*--处理要求 在sql数据库里有一个名为Pos200502的Database,每个月会有一个类似于这样名称(Pos200502 Pos200503)的database 我该如何利用sql server的自动作业+一段存储过程,实现... 阅读全文
posted @ 2007-06-29 16:47 伊凡 阅读(319) 评论(0) 推荐(0)
逐记录导出text/ntext字段值为文本文件

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3851/3851741.xml?temp=.4726831--*/ --测试数据create table tb(id varchar(50) primary key,detail text)insert tb select 'aaa','11111'union all select 'bbb','43... 阅读全文
posted @ 2007-06-29 16:46 伊凡 阅读(389) 评论(0) 推荐(0)
无规律自定义分段的分类汇总+交叉表处理

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3845/3845290.xml?temp=.3689386--*/ --测试数据create table tb(编号 int,性质 varchar(10),数量 int,指标1 decimal(10,1),指标2 decimal)insert tb select 1 ,'00' ,10,1.1 ,10... 阅读全文
posted @ 2007-06-29 16:45 伊凡 阅读(370) 评论(0) 推荐(0)
随机排序分页处理示例

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3845/3845647.xml?temp=.7272455--*/ /*--处理要求 用如下语句可以实现随机排序:select * from xiaofei where status=1 order by newid() 这样的话每次用户刷新页面排序就会变.现在我想做成不同用户进来页面看到的排序都不一... 阅读全文
posted @ 2007-06-29 16:45 伊凡 阅读(519) 评论(0) 推荐(0)
逐月对比的交叉表处理

摘要:/*--原帖地址:http://community.csdn.net/Expert/topic/3841/3841808.xml?temp=.4308588--*/ --测试数据create table tb(year int,month int,No varchar(10),Name varchar(10),部门 varchar(10),工资 int)insert tb select 2004,... 阅读全文
posted @ 2007-06-29 16:44 伊凡 阅读(204) 评论(0) 推荐(0)
特殊分页处理

摘要:原帖地址:http://community.csdn.net/Expert/topic/3662/3662135.xml?temp=.4289972 --测试数据create table tb(ID int primary key,grade varchar(10),uptime datetime)insert tb select 1 ,'a','2004-12-11'union all sele... 阅读全文
posted @ 2007-06-29 16:44 伊凡 阅读(240) 评论(0) 推荐(0)
自定义公式的计算处理

摘要:原帖地址:http://community.csdn.net/Expert/topic/3485/3485588.xml?temp=.8813745 --示例数据create table sale(date datetime,code varchar(10),amt int)insert sale select '2004-10-22','aa',15000union all select '... 阅读全文
posted @ 2007-06-29 16:41 伊凡 阅读(725) 评论(0) 推荐(0)
树形数据转换

摘要:原帖地址:http://community.csdn.net/Expert/topic/3663/3663934.xml?temp=.9100458 --测试数据create table PROJECT(id int,name nvarchar(20),parent_id int)insert PROJECT select 1,'所有项目',nullunion all select 2,... 阅读全文
posted @ 2007-06-29 16:41 伊凡 阅读(479) 评论(0) 推荐(0)
动态关联表

摘要:原帖地址:http://community.csdn.net/Expert/topic/3452/3452577.xml?temp=.1377375 --示例数据create table [table](A sysname,B varchar(10))insert [table] select 'table_1','a'union all select 'table_2','b' cre... 阅读全文
posted @ 2007-06-29 16:40 伊凡 阅读(315) 评论(0) 推荐(0)
模拟多级表头的分组统计

摘要:原帖地址:http://community.csdn.net/Expert/topic/3434/3434688.xml?temp=3.246486E-03 --测试数据create table 单位表 (单位代码 varchar(10),单位名称 varchar(50))insert 单位表 values('01' ,'中国单位') --1级insert 单位表... 阅读全文
posted @ 2007-06-29 16:39 伊凡 阅读(357) 评论(0) 推荐(0)
动态分组查询

摘要:原帖地址:http://community.csdn.net/Expert/topic/3428/3428792.xml?temp=.6476251 --示例数据create table 表(ID int,NUM int)insert 表 select 1,2union all select 2,3union all select 3,2union all select 4,2union all ... 阅读全文
posted @ 2007-06-29 16:38 伊凡 阅读(448) 评论(0) 推荐(0)

1 2 3 下一页
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3