2

I'm having a SQL issue and have tried multiple combinations to no avail. I've tried commas, and also semicolons, after the first two ), all three ), just the last ), on all of these. No such luck. Please help me fix the query. Thanks in advance!

I have done due diligence and came across several sites (I can only post two links because of reputatoin) these: 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

THIS WORKS, but very cumbersome to do 20 files.

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
4

3 回答 3

1

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

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
于 2013-07-03T19:43:19.887 回答
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
于 2013-07-03T21:21:58.277 回答
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
于 2013-07-03T19:48:34.737 回答