SET NOCOUNT ON
DECLARE @LogicalFileName sysname,
@MaxMinutes INT,
@NewSize INT
USE tablename -- 要操作的数据库名
Select @LogicalFileName='tablename_log', --日志文件名
@MaxMinutes=10, -- Limit on time allowed to wrap log.
@NewSize=1 -- 你想设定的日志文件的大小(M)
-- Setup / initialize
DECLARE @OriginalSize int
Select @OriginalSize=size
FROM sysfiles
Where name=@LogicalFileName
Select 'Original Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'
FROM sysfiles
Where name=@LogicalFileName
Create TABLE DummyTrans
(DummyColumn char (8000) not null)
DECLARE @Counter INT,
@StartTime DATETIME,
@TruncLog VARCHAR(255)
Select @StartTime=GETDATE(),
@TruncLog='BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY'
DBCC SHRINKFILE (@LogicalFileName, @NewSize)
EXEC (@TruncLog)
-- Wrap the log if necessary.
WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired
AND @OriginalSize=(Select size FROM sysfiles Where name=@LogicalFileName)
AND (@OriginalSize * 8 /1024) > @NewSize
BEGIN -- Outer loop.
Select @Counter=0
WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
BEGIN -- update
Insert DummyTrans VALUES ('Fill Log')
Delete DummyTrans
Select @Counter=@Counter + 1
END
EXEC (@TruncLog)
END
Select 'Final Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),size) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'
FROM sysfiles
Where name=@LogicalFileName
Drop TABLE DummyTrans
SET NOCOUNT OFF
更改某个表
exec sp_changeobjectowner 'tablename','dbo'
存储更改全部表
Create PROCEDURE dbo.User_ChangeObjectOwnerBatch
@OldOwner as NVARCHAR(128),
@NewOwner as NVARCHAR(128)
AS
DECLARE @Name as NVARCHAR(128)
DECLARE @Owner as NVARCHAR(128)
DECLARE @OwnerName as NVARCHAR(128)
DECLARE curObject CURSOR FOR
select 'Name'=name,
'Owner'=user_name(uid)
from sysobjects
where user_name(uid)=@OldOwner
order by name
OPEN curObject
FETCH NEXT FROM curObject INTO @Name, @Owner
WHILE(@@FETCH_STATUS=0)
BEGIN
if @Owner=@OldOwner
begin
set @OwnerName=@OldOwner + '.' + rtrim(@Name)
exec sp_changeobjectowner @OwnerName, @NewOwner
end
-- select @name,@NewOwner,@OldOwner
FETCH NEXT FROM curObject INTO @Name, @Owner
END
close curObject
deallocate curObject
GO
循环写入数据
declare @i int
set @i=1
while @i<30
begin
insert into test (userid) values(@i)
set @i=@i+1
有关sql语句大全的介绍就到这里,希望对大家都有所帮助!想要详细了解sql语句大全,可以继续关注sql语句入门的最新动态 。
【sql语句大全_sql语句入门】
- 中国古代怪物大全:古代77个怪物及出处介绍
- 女装品牌大全排行榜,盘点最受欢迎的女装品牌
- 智能报警器报价大全
- 世界杯夺冠次数排名历届世界杯冠军名单大全
- 牛油果和什么搭配榨汁 牛油果榨汁搭配大全
- 热门无线蓝牙耳机大全 无线蓝牙耳机排行榜
- 玻璃砖贴图多少钱一平米! 玻璃砖贴图大全
- 电饼铛食谱大全,电饼铛这么做美食真的是好吃
- 世界女鞋品牌大全排行榜,44个女鞋品牌你拥有哪一款
- NBA全明星赛纪录大全NBA全明星赛得分纪录