Some Test

----------------------------------------------------------------------------
-------------------------------启用CLR集成----------------------------------
----在你开始用C#写存储过程之前,必须要启用你的SQL Server的CLR集成特性,默认情况它是不启用的.
----打开你的SQL Server Management Studio并执行如下脚本

EXECUTE sp_configure 'clr enabled'   -------查看状态--------

EXECUTE sp_configure 'clr enabled',1   -------两个参数:1-启用clr,0-禁用clr------

----这里,我们执行了系统存储过程“sp_configure”,为其提供的两个参数分别为:“clr enabled”和“1”.
----如果要停用CLR集成的话也是执行这个存储过程,只不过第二个参数要变为“0”而已.
----"Configuration option 'clr enabled' changed from 1 to 1. Run the RECONFIGURE statement to install."
---按提示(配置选项 'clr enabled' 已从 0 更改为 1.请运行 RECONFIGURE 语句进行安装。)
----另外,为了使新的设置产生效果,不要忘记调用“RECONFIGURE”.运行此句

RECONFIGURE
----------------------------------------------------------------------------

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

IF OBJECT_ID('Test_UserList','U') is not null
drop table [Test_UserList]
GO
CREATE TABLE [dbo].[Test_UserList] (
[TUL_ID] BIGINT IDENTITY(1,1) NOT NULL,
[TUL_NAME] nvarchar(50) NULL,
[TUL_Desc] nvarchar(200) NULL,
[TUL_level] BIGINT NULL,
[TUL_BoosID] [int] NULL
) ON [PRIMARY]

USE [MyTest]
GO
/****** Object:  StoredProcedure [dbo].[UserList_INSERT]    Script Date: 06/17/2008 10:56:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[UserList_INSERT]
(
 @NAME NVARCHAR(50),
 @DESC NVARCHAR(50),
 @BOOSID BIGINT
)
AS
SET NOCOUNT ON;

DECLARE @LEVEL BIGINT;
DECLARE @TranCounter INT;
SET @TranCounter = @@TRANCOUNT;


 SELECT @LEVEL=[TUL_level]+1 FROM [Test_UserList] WHERE [TUL_ID]=@BOOSID


IF @LEVEL=0 OR @LEVEL IS NULL
BEGIN
 SET @LEVEL=1;
 SET @BOOSID=0;
END

 --BEGIN TRANSACTION
 IF @TranCounter = 0
  BEGIN TRANSACTION;

 --Verify Foreign Keys
 --Insert Data
 DECLARE @ErrCode INT;


 INSERT INTO [Test_UserList]
 (
  [TUL_NAME],
  [TUL_Desc],
  [TUL_level],
  [TUL_BoosID]
 )
 values
 (
  @NAME,
  @DESC,
  @LEVEL,
  @BOOSID
 )

 SET @ErrCode = @@ERROR;

 IF @ErrCode = 0
  BEGIN
  --COMMIT TRANSACTION
  IF @TranCounter = 0
   IF (XACT_STATE()) = 1
    COMMIT TRANSACTION
  END
 --ROLLBACK TRANSACTION
 IF @TranCounter = 0
  IF (XACT_STATE()) <> 0
   ROLLBACK TRANSACTION

-------------------------------------------------------------------


dbo.UserList_INSERT 'gyf','rrrr',0;

select * from Test_UserList


WITH IamV AS(
SELECT [TUL_ID],[TUL_NAME],[TUL_Desc],[TUL_level],[TUL_BoosID]
FROM Test_UserList(NOLOCK)
WHERE [TUL_BoosID]=3
UNION ALL
SELECT a.[TUL_ID],a.[TUL_NAME],a.[TUL_Desc],a.[TUL_level],a.[TUL_BoosID]
FROM IamV z
INNER JOIN Test_UserList a on z.[TUL_ID]=a.[TUL_BoosID]
)
SELECT * from IamV
------------------------------------------------------------------
------------------------------------------------------------------
------------------------------------------------------------------

/*

OBJECT_ID():返回数据库对象标识号。N是显式的将非unicode字符转成unicode字符,它来自 SQL-92 标准中的 National(Unicode)数据类型,用于扩展和标准化,在这里可以不用,写作object_id(PerPersonData)。

OBJECTPROPERTY():返回当前数据库中对象的有关信息.BOOL 1表“真”。同样可以写成OBJECTPROPERTY(id,IsUserTable) = 1。


整条语句的意思是判断数据库里有没有存在PerPersonData这样一张表。

*/


 

--CTE是Common Table Expression的简写,翻译成中文就是通用表表达式,它可以在select,insert或者update中使用。
--为了说明问题,我们先随便建张表,插入几条数据:
--知识点:WITH AS, ROW_NUMBER(),OVER(),object_id()
--这是2005提供的一个新功能,叫CTE(公用表表达式)
--其实他就是一个临时视图,因此使用的时候必须
--1 前一个语句必须以分号结尾
--2 本质上,CTE是一个临时结果集,它仅仅存在于它发生的语句中。
--  因此当你第二次调用他的时候必须再次声明一个CTE,这样这个CTE才存在与这个语句中
--
--与派生表不同,CTE能够引用自己本身。如果您不必存储视图,您可以用一个CTE来代替它。
--在一个语句中,您还可以多次引用CTE。应用CTE,您可以通过一个派生栏对结果进行分组。
--用CTE来实现递归是他的最大特点

if object_id('t','U') is not null --用object_id函数判断表是否在数据库中存在很简洁
drop table t;
GO
create table t(c1 int,c2 decimal,c3 int);
GO
INSERT INTO t
SELECT c1 = 1,c2 = 5.0,c3=10
UNION
SELECT c1 = 2,c2 = 5.5,c3=10
UNION
SELECT c1 = 3,c2 = 5.0,c3=20
UNION
SELECT c1 = 4,c2 = 5.5,c3=20
--下面我们使用CTE写一个分页的sql语句
GO
WITH t_cn AS
(   
select c1,c2,c3,rn = ROW_NUMBER()
OVER(ORDER BY c1 DESC)
FROM t WHERE 0 = 0 --可以在此处添加一些条件
)
SELECT c1,c2,c3,rn FROM t_cn WHERE rn between 2 and 5
SELECT totalCn = COUNT(*) FROM t WHERE 0 = 0


 
PRINT CONVERT(NVARCHAR(50),GETDATE(),13);

WITH aab(t,b) AS
(
 SELECT 1, CONVERT(NVARCHAR(50),GETDATE(),13)
 UNION ALL
 SELECT t+1, CONVERT(NVARCHAR(50),GETDATE(),13) FROM aab
 WHERE t < 20000
)
SELECT * FROM aab
--UNION ALL
--SELECT * FROM aab
 OPTION (MAXRECURSION 32767)
 

PRINT CONVERT(NVARCHAR(50),GETDATE(),13)


-----------------------------------------------------------
-----------------------------------------------------------


WITH ctedt(dt) AS
(
 SELECT 1
 UNION ALL
 SELECT dt + 1 FROM ctedt
 WHERE dt < 1000
),
cteds(ds) AS
(
 SELECT 1000
 UNION ALL
 SELECT ds - 1 FROM cteds
 WHERE ds >1
)
SELECT ctedt.dt,
cteds.ds
FROM cteds
INNER JOIN ctedt ON ds=dt
 OPTION (MAXRECURSION 32767)


  ----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

 

/*
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
*/
SET STATISTICS IO ON
SET STATISTICS TIME ON

 SELECT TOP 10 *
 FROM UserTraces AS ut1
 WHERE ActionID<>2
  AND NOT EXISTS(
   SELECT 1
   FROM UserTraces
   WHERE ExtensionID1=ut1.ExtensionID1 AND ActionID<>2 AND CreateDate>ut1.CreateDate
   )
 ORDER BY CreateDate DESC

 SELECT TOP 10 *
  FROM UserTraces AS t1
   Where EXISTS
   (
      SELECT *
      FROM UserTraces AS t2
      WHERE ActionID<>2
      GROUP BY ExtensionID1
      HAVING ExtensionID1 = t1.ExtensionID1
    and max(CreateDate) = t1.CreateDate
   )
   ORDER BY CreateDate DESC

SET STATISTICS TIME OFF
SET STATISTICS IO OFF


select top 2 * from A order by newid()
   
SELECT NEWID()


----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------
--1.请问MDF和LDF文件如何还原为数据库实例? 

-- 附加数据库就可以完成.   
--  附加数据库:    
--    企业管理器  
--  --右键"数据库"  
--  --所有任务  
--  --附加数据库  
--  --选择你的.mdf文件名  
--  --确定  
--  --如果提示没有.ldf文件,是否创建,选择"是"  
 
--  查询分析器中的方法:  
--  --有数据文件及日志文件的情况  
--  sp_attach_db   '数据库名'  
--  ,'数据文件名(*.mdf注意要带目录)'   --后面可以是用,分隔的该数据库的多个数据文件  
--  ,'日志文件名(*.ldf注意要带目录)'--后面可以是用,分隔的该数据库的多个日志文件  
--   
--  --如果只有数据文件的情况  
--  sp_attach_single_file_db   '数据库名'  
--  ,'数据文件名(*.mdf注意要带目录)'   --后面可以是用,分隔的该数据库的多个数据文件  
--   


--EXEC sp_attach_db @dbname= N'ShopData',
--  @filename1=N'E:\IamV\ShopStiteSQLDataBase\ShopData_Data.MDF',
--  @filename2=N'E:\IamV\ShopStiteSQLDataBase\ShopData_Log.LDF'
--------------------------------------------------------------------------------------

--------------------------------------------------------------

begin transaction

commit transaction

rollback transaction

select @@TRANCOUNT

select XACT_STATE()
----------------------------------------------------------------



 

转载于:https://www.cnblogs.com/iamv/archive/2008/06/18/1224524.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mircea has n pictures. The i-th picture is a square with a side length of si centimeters. He mounted each picture on a square piece of cardboard so that each picture has a border of w centimeters of cardboard on all sides. In total, he used c square centimeters of cardboard. Given the picture sizes and the value c, can you find the value of w? A picture of the first test case. Here c=50=52+42+32, so w=1 is the answer. Please note that the piece of cardboard goes behind each picture, not just the border. Input The first line contains a single integer t (1≤t≤1000) — the number of test cases. The first line of each test case contains two positive integers n (2≤n≤2⋅105) and c (1≤c≤1018) — the number of paintings, and the amount of used square centimeters of cardboard. The second line of each test case contains n space-separated integers si (1≤si≤104) — the sizes of the paintings. The sum of n over all test cases doesn't exceed 2⋅105. Additional constraint on the input: Such an integer w exists for each test case. Please note, that some of the input for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++). Output For each test case, output a single integer — the value of w which was used to use exactly c squared centimeters of cardboard. Example inputCopy 10 3 50 3 2 1 1 100 6 5 500 2 2 2 2 2 2 365 3 4 2 469077255466389 10000 2023 10 635472106413848880 9181 4243 7777 1859 2017 4397 14 9390 2245 7225 7 176345687772781240 9202 9407 9229 6257 7743 5738 7966 14 865563946464579627 3654 5483 1657 7571 1639 9815 122 9468 3079 2666 5498 4540 7861 5384 19 977162053008871403 9169 9520 9209 9013 9300 9843 9933 9454 9960 9167 9964 9701 9251 9404 9462 9277 9661 9164 9161 18 886531871815571953 2609 10 5098 9591 949 8485 6385 4586 1064 5412 6564 8460 2245 6552 5089 8353 3803 3764 outputCopy 1 2 4 5 7654321 126040443 79356352 124321725 113385729 110961227 Note The first test case is explained in the statement. For the second test case, the chosen w was 2, thus the only cardboard covers an area of c=(2⋅2+6)2=102=100 squared centimeters. For the third test case, the chosen w was 4, which obtains the covered area c=(2⋅4+2)2×5=102×5=100×5=500 squared centimeters. c++实现
最新发布
07-22

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值