随笔分类 -  SQL

摘要:首先准备两台服务器:发布服务器A,订阅服务器B,两台服务器的版本一样,服务的账户【‘网络服务’】也要一样,代理服务的账户自己新创建一个账户(eg:vpn/vpn)。 1.创建发布服务。 1.1连接发布服务器A, 1.2选择数据库,点一下 1.3下一步, 有“快照发布”和“事务发布”(本次只介绍这两种 阅读全文
posted @ 2017-09-21 13:33 csdnbbs 阅读(346) 评论(0) 推荐(0)
摘要:--1.备份主数据库backup database testto disk ='D:\test.bak';--2.还原备份,生成镜像数据库(镜像服务器)Restore database testfrom disk='D:\test.bak'with NoRecovery,--保持数据一直处于恢复状态move 'Test' to 'd:\test.mdf',move 'Test_log' to 'd:\test_log.ldf';--3.1创建日志传端口create endpoint Mirrorin 阅读全文
posted @ 2013-04-05 11:54 csdnbbs 阅读(407) 评论(0) 推荐(0)
摘要:create table #tb(name varchar(32),kechen varchar(32),score float); insert into #tb values('小明','数学',99) insert into #tb values('小明','英语',60) insert into #tb values('小明','语文',100) insert into #tb values('小强','数学',29) insert into #tb valu 阅读全文
posted @ 2013-04-04 22:25 csdnbbs 阅读(153) 评论(0) 推荐(0)
摘要:output 可以把对表的:添加,删除,更新操作数据插入临时表。create table #tb(id int,name varchar(32));declare @tb table(id int,name varchar(32));/* 添加insert into #tb(id,name) output inserted.id,inserted.name into @tb values(1 ,'AAA' ) *//* 删除delete #tboutput deleted.id,deleted.name into @tb where id=1*/--更新update #tb.. 阅读全文
posted @ 2013-04-04 21:58 csdnbbs 阅读(157) 评论(0) 推荐(0)
摘要:select i.name,[Type]=case when i.is_unique=1 and is_primary_key=1 then '主键' when i.is_unique=1 and is_primary_key=0 then '唯一键' else '索引' end,TypeRemark=i.type_desc from sys.indexes i where i.[object_id]=object_id('表名') and i.name is not null unio... 阅读全文
posted @ 2013-03-04 23:11 csdnbbs 阅读(317) 评论(0) 推荐(0)
摘要:CREATE PROC sp_PageView @sql ntext, --要执行的sql语句@PageCurrent int=1, --要显示的页码@PageSize int=10, --每页的大小@PageCount int OUTPUT --总页数ASSET NOCOUNT ONDECLARE @p1 int--初始化分页游标EXEC sp_cursoropen @cursor=@p1 OUTPUT,@stmt=@sql,@scrollopt=1,@ccopt=1,@rowcount=@PageCount OUTPUT --计算总页数I... 阅读全文
posted @ 2013-01-11 09:54 csdnbbs 阅读(171) 评论(0) 推荐(0)
摘要:要求:求每个人最差的那一门课程及分数(如下图) 名字 科目 成績 小明 英語 80 小紅 英語 70with tb(name,kemu,score) as( select '小明','語文',90 union all select '小明','數學',85 union all select '小明','英語',80 union all select '小紅','語文',80 union all select '小紅','數學',85 u 阅读全文
posted @ 2012-12-06 13:12 csdnbbs
摘要:查找 从A到 I怎么走路线create table #y([f1] varchar(1),[f2] varchar(1))insert #y select 'A','B' union all select 'A','F' union all select 'A','G' union all select 'B','C' union all select 'B','G' union all select 'B',' 阅读全文
posted @ 2012-12-06 12:49 csdnbbs