sql修改文件语句

时间:2013-07-03 19:36:32

标签: sql sql-server tsql

我遇到了SQL问题并尝试了多种组合无济于事。在所有这些之后,我已经尝试过逗号,也有分号,在前两个之后),所有三个,只是最后一个)。没有这样的运气。请帮我修复查询。提前谢谢!

我已经做了尽职调查并遇到了几个网站(我只能发布两个链接因为reputatoin)这些: Create database using script at the default path? http://www.sqlteam.com/forums/topic.asp?topic_id=148732

USE master
GO
ALTER DATABASE location_cust_db
MODIFY FILE
(
    NAME = location_cust_db_data1,
    MAXSIZE = UNLIMITED,
)
(
    NAME = location_cust_db_data2,
    MAXSIZE = UNLIMITED,
)
(
    NAME = location_cust_db_data3,
    MAXSIZE = UNLIMITED,
)
GO

USE master
GO
ALTER DATABASE location_cust_db
MODIFY FILE (NAME = location_cust_db_data1, MAXSIZE = UNLIMITED)
MODIFY FILE (NAME = location_cust_db_data2, MAXSIZE = UNLIMITED)
MODIFY FILE (NAME = location_cust_db_data3, MAXSIZE = UNLIMITED)
GO

这样做,但是做20个文件非常麻烦。

USE master
GO
ALTER DATABASE location_cust_db
MODIFY FILE
(NAME = location_cust_db_data1,
MAXSIZE = UNLIMITED)


USE master
GO
ALTER DATABASE location_cust_db
MODIFY FILE
(NAME = location_cust_db_data2,
MAXSIZE = UNLIMITED)
GO

USE master
GO
ALTER DATABASE location_cust_db
MODIFY FILE
(NAME = location_cust_db_data3,
MAXSIZE = UNLIMITED)
GO

3 个答案:

答案 0 :(得分:1)

您的第三个选项最接近 - 每次修改都必须在单独的ALTER DATABASE命令中,但您可以省略USE语句,因为您总是从MASTER运行:< / p>

USE master
GO

ALTER DATABASE location_cust_db
MODIFY FILE (NAME = location_cust_db_data1, MAXSIZE = UNLIMITED)
GO

ALTER DATABASE location_cust_db
MODIFY FILE (NAME = location_cust_db_data2, MAXSIZE = UNLIMITED)
GO

ALTER DATABASE location_cust_db
MODIFY FILE (NAME = location_cust_db_data3, MAXSIZE = UNLIMITED)
GO

..etc

答案 1 :(得分:0)

如果我的问题是正确的,那么这个会帮助你

begin
use master;
declare @com nvarchar(1024);
set @com='ALTER DATABASE location_cust_db MODIFY FILE (NAME = location_cust_db_data';
declare @i int;
set @i=1;
while(@i<20) begin
      set @com=@com+str(@i)+' ,MAXSIZE = UNLIMITED);'
      exec (@com);
      set @i=@i+1;
     end
end

答案 2 :(得分:0)

use [location_cust_db]
GO

declare csDBFiles cursor local fast_forward for
select
    'ALTER DATABASE [' + DB_NAME() + '] MODIFY FILE (NAME = [' + name + '], MAXSIZE = UNLIMITED)'
from
    sys.database_files

open csDBFiles

declare @stmt varchar(2000)

fetch next from csDBFiles into @stmt
while @@fetch_status = 0
begin
    print @stmt
    print 'GO'
    exec(@stmt)

    fetch next from csDBFiles into @stmt
end

close csDBFiles
deallocate csDBFiles
GO