Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Tuesday, March 27, 2012

changing collation_name of SqlServer Database

Hi

I want to change collation_name of my SqlServer Database by running a script. But I don't know how.
Please help me.

ThanksYou should be able to do this:


ALTER DATABASE myDatabase COLLATE SQL_Latin1_General_CP1_CI_AS

This will change the default collation for any new objects added to the database. To change the collation of existing objects you will need to run an ALTER TABLE command against each table.

Terrisql

Sunday, March 25, 2012

Changing all existing tables collations in one step

If you're wanting to change the whole collation of your database then
(in SQL 2000) the best way is to script out the db, recreate it with
the new collation as default, then DTS your data across. I think that
if you changed it table by table then every new table you create will
then have to be changed as well.
Hopefully there's something in SQL 2005 that allows a complete db
collation change, as I expect most people have run into the issue of a
database being restored from a backup from a server that used a
different collation (I often found for some reason the collation got
set to LATIN1_GENERAL_CPL_CI_AS on peoples default install of SQL for
no apparent reason).Thank you.
"Will" wrote:

> If you're wanting to change the whole collation of your database then
> (in SQL 2000) the best way is to script out the db, recreate it with
> the new collation as default, then DTS your data across. I think that
> if you changed it table by table then every new table you create will
> then have to be changed as well.
>
> Hopefully there's something in SQL 2005 that allows a complete db
> collation change, as I expect most people have run into the issue of a
> database being restored from a backup from a server that used a
> different collation (I often found for some reason the collation got
> set to LATIN1_GENERAL_CPL_CI_AS on peoples default install of SQL for
> no apparent reason).
>

Sunday, March 11, 2012

Change values in SSIS.

Howdy all. In DTS there was a way too change the values of a column during
and export to another table using ActiveX Script:
Source:
Table1
column1
column2
Destination
Table2
column1 (I want this to contain the exact values from Table1.column1)
column2 (I want this to contain the values of Table1.column2 + 10)
Basically you would do this through the mappings, instead of a Copy Column,
you would use an AxtiveX script for that column. How can this be done in
SSIS?
TIA, ChrisRThanks.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:5FAF7EA7-D0E7-41FB-AF37-B70DA73AE95E@.microsoft.com...
> Hi Chris
> You can use a script component as a transform task see
> http://www.sqlis.com/default.aspx?307,1
> John
> "ChrisR" wrote:
> > Howdy all. In DTS there was a way too change the values of a column
during
> > and export to another table using ActiveX Script:
> >
> > Source:
> > Table1
> > column1
> > column2
> >
> > Destination
> > Table2
> > column1 (I want this to contain the exact values from Table1.column1)
> > column2 (I want this to contain the values of Table1.column2 + 10)
> >
> > Basically you would do this through the mappings, instead of a Copy
Column,
> > you would use an AxtiveX script for that column. How can this be done in
> > SSIS?
> >
> > TIA, ChrisR
> >
> >
> >
> >
> >

Sunday, February 19, 2012

Change servername based on logon server

Hi
We are to use an application on two replicated sites, the application uses a
user dsn.
We propose to use a reg file attached to a logon script to amend the server
name so that users with laptops can move transparently between sites.
Is this the best method or is there another?
Thanks
BA registry file? Sounds dangerous.
"Ben" <Ben@.Newsgroups.microsoft.com> wrote in message
news:OoEZPKocGHA.1324@.TK2MSFTNGP04.phx.gbl...
> Hi
> We are to use an application on two replicated sites, the application uses
> a
> user dsn.
> We propose to use a reg file attached to a logon script to amend the
> server
> name so that users with laptops can move transparently between sites.
> Is this the best method or is there another?
> Thanks
> B
>|||Hi
Yes the server name is stored in the HKCU.
We use reg files regularly to update other required settings to the HKCU.
But is there a reccomended method?
Thanks
B
"Mike C#" <xxx@.yyy.com> wrote in message news:tAR8g.506$Ut2.358@.fe09.lga...
> A registry file? Sounds dangerous.
> "Ben" <Ben@.Newsgroups.microsoft.com> wrote in message
> news:OoEZPKocGHA.1324@.TK2MSFTNGP04.phx.gbl...
uses[vbcol=seagreen]
>|||That's probably the easiest method, but it would be really easy for some to
alter the reg files and screw up a registry pretty badly. For constantly
changing servers, maybe a File DSN would be a more secure bet? For security
purposes, if you want to mess directly with the registry, maybe adding a
short application to the logon script that only touches the registry keys
you really want to change would be a more secure bet? I'd just be a little
hesitant about installing nondescriminating reg files on user computers.
"Ben" <Ben@.Newsgroups.microsoft.com> wrote in message
news:eLjhcPtdGHA.3364@.TK2MSFTNGP05.phx.gbl...
> Hi
> Yes the server name is stored in the HKCU.
> We use reg files regularly to update other required settings to the HKCU.
> But is there a reccomended method?
> Thanks
> B
> "Mike C#" <xxx@.yyy.com> wrote in message
> news:tAR8g.506$Ut2.358@.fe09.lga...
> uses
>|||Hi Mike,
Thanks for your post, and sorry for the delay in replying, sadly our
Software Vendor only Supports User and System DSNs.
The logon script / reg file is in a secure location on the server where
users do not have write access, it will run on each boot so if the user
messes with the registry: after a boot we are sorted again. Thankfully I
think they all have not even heard of a registry let alone know how to open
regedit :-)
Thanks
B
"Mike C#" <xxx@.yyy.com> wrote in message news:C7t9g.164$yJ6.58@.fe12.lga...
> That's probably the easiest method, but it would be really easy for some
to
> alter the reg files and screw up a registry pretty badly. For constantly
> changing servers, maybe a File DSN would be a more secure bet? For
security
> purposes, if you want to mess directly with the registry, maybe adding a
> short application to the logon script that only touches the registry keys
> you really want to change would be a more secure bet? I'd just be a
little
> hesitant about installing nondescriminating reg files on user computers.
> "Ben" <Ben@.Newsgroups.microsoft.com> wrote in message
> news:eLjhcPtdGHA.3364@.TK2MSFTNGP05.phx.gbl...
HKCU.[vbcol=seagreen]
>|||Hi Ben,
I'd still be concerned that the registry file could be altered at some point
before being installed on the system (a disgruntled IT employee? hacker?
curious employee? who knows...) Of course that's just my initial thoughts,
but I'd be hesitant to send .reg files to be directly imported into the
registry. Personally I prefer the idea of some form of small validating
application called from the script to ensure direct registry updates are
within a very well-defined and narrow scope. In fact, since you're doing
DSNs, I might even go a step further and suggest using the ODBC API to
update them instead of writing the registry directly. Presumably the ODBC
API offers additional validation of the DSN as well (i.e., length of DSN
name, etc.)
Anyway, best of luck!
Mike
"Ben" <Ben@.Newsgroups.microsoft.com> wrote in message
news:OURbJ2qfGHA.4864@.TK2MSFTNGP05.phx.gbl...
> Hi Mike,
> Thanks for your post, and sorry for the delay in replying, sadly our
> Software Vendor only Supports User and System DSNs.
> The logon script / reg file is in a secure location on the server where
> users do not have write access, it will run on each boot so if the user
> messes with the registry: after a boot we are sorted again. Thankfully I
> think they all have not even heard of a registry let alone know how to
> open
> regedit :-)
> Thanks
> B
> "Mike C#" <xxx@.yyy.com> wrote in message news:C7t9g.164$yJ6.58@.fe12.lga...
> to
> security
> little
> HKCU.
>

Change script from MSAccess to SQL access.

I'm using this script I found on the web. After some tweaking here and there, it works great. I'd like to change it to pull data from a SQL source instead of Access. Anyone know how to do this, give me some pointers?

Here is the script
*****************************************************************************************************************

<%@. LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
Dim DATA_PATH, Conn, DataRecords, email, user, pass, sendmail
'Maps to database. Change to your database path.
DATA_PATH=Server.Mappath("membersdb.mdb")
' Create and intiate data connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionTimeout = 15
Conn.CommandTimeout = 30
Conn.Open "DBQ=" & DATA_PATH & ";Driver={Microsoft Access Driver (*.mdb)}; DriverId=25;MaxBufferSize=8192;Threads=20;", "admin", "password"
Set DataRecords = Server.CreateObject("ADODB.Recordset")
email=request.form("email")
'The magic query to look for registered members in the database
DataRecords.Open "SELECT * FROM MEMBERS WHERE email = '" & email & "'", Conn, 0, 1
%>
<%
'checks if email address exists in the database before sending a message.
if DataRecords.EOF then
%>
We could not find <%=email%> in our database.
<% Else %>
<%
'sets variables
email = request.form("email")
'chooses username and password from database that correspond to submitted email address.
user = DataRecords.Fields("usernames")
pass = DataRecords.Fields("password")
Set sendmail = Server.CreateObject("CDONTS.NewMail")
'put the webmaster address here
sendmail.From = "Someone@.somewhere.com"
'The mail is sent to the address entered in the previous page.
sendmail.To = email
'Enter the subject of your mail here
sendmail.Subject = "Membership Login Information"
'This is the content of thr message.
sendmail.Body = "Per your request your account login information is: " & vbCrlf & vbCrlf _
& "Username=" & user & vbCrlf _
& "Password=" & pass & vbCrlf
'this sets mail priority.... 0=low 1=normal 2=high
'sendmail.Importance = 3 commented out causes a error for a call or procedure (line 41)
sendmail.Send
%>
We just sent your login information to <%=email%>.
You should receive it shortly.
<%
' Close Data Access Objects and free connection variables
Conn.Close
Set DataRecords = Nothing
Set Conn = Nothing
Set sendmail = Nothing
%><%end if%>

***************************************************************************************************************
And here's my SQL connection stuff
Private Sub Class_Initialize()
ConnectionString = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=ABC;Data Source=xx.xx.xx.xx"
User = "usr"
Password = "pswrd"
Set Converter = New clsConverter
Converter.DateFormat = Array("yyyy", "-", "mm", "-", "dd", " ", "HH", ":", "nn", ":", "ss")
Converter.BooleanFormat = Array(1, 0, Empty)
Set objConnection = Server.CreateObject("ADODB.Connection")
Database = "MSSQLServer"
Set Errors = New clsErrors
End Sub
****************************************************************************************************************

sure would appreciate some help!

You can use a different driver in the connection string. Connectionstrings can be found here: www.connectionstrings.com

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

As Jens suggested you should be able to simply replace

Conn.Open "DBQ=" & DATA_PATH & ";Driver={Microsoft Access Driver (*.mdb)}; DriverId=25;MaxBufferSize=8192;Threads=20;", "admin", "password"

with

Conn.Open "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=ABC;Data Source=xx.xx.xx.xx;Password=<your pwd here>"

Please be careful about storing the password into the script itself, it is not secure.

HTH,

Jivko Dobrev - MSFT
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Thursday, February 16, 2012

Change Recovery Model: Without GUI

I need a script that I can change the SQL Server 2000
database from Recovery Model: Full to Simple.
Please help me with this task?
Dan
alter database FOO set recovery simple
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:17ea901c449a8$fffd24d0$a501280a@.phx.gbl...
> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan
|||alter database [your database] set recovery full
Eric Li
SQL DBA
MCDBA
Dan wrote:

> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan
|||Oops, should be set recovery simple
Eric Li
SQL DBA
MCDBA
Eric.Li wrote:

> alter database [your database] set recovery full
>

Change Recovery Model: Without GUI

I need a script that I can change the SQL Server 2000
database from Recovery Model: Full to Simple.
Please help me with this task?
Danalter database FOO set recovery simple
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:17ea901c449a8$fffd24d0$a501280a@.phx
.gbl...
> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan|||alter database [your database] set recovery full
Eric Li
SQL DBA
MCDBA
Dan wrote:

> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan|||Oops, should be set recovery simple
Eric Li
SQL DBA
MCDBA
Eric.Li wrote:

> alter database [your database] set recovery full
>

Change Recovery Model: Without GUI

I need a script that I can change the SQL Server 2000
database from Recovery Model: Full to Simple.
Please help me with this task?
Danalter database FOO set recovery simple
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:17ea901c449a8$fffd24d0$a501280a@.phx.gbl...
> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan|||alter database [your database] set recovery full
--
Eric Li
SQL DBA
MCDBA
Dan wrote:
> I need a script that I can change the SQL Server 2000
> database from Recovery Model: Full to Simple.
> Please help me with this task?
> Dan|||Oops, should be set recovery simple
--
Eric Li
SQL DBA
MCDBA
Eric.Li wrote:
> alter database [your database] set recovery full
>

Sunday, February 12, 2012

Change object all object onwer

I have a script like below to change all the object owner from "xxxxx"
to "dbo".
==================================== declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCHChange one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegroups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>

Change object all object onwer

I have a script like below to change all the object owner from "xxxxx"
to "dbo".
====================================
declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCH
Change one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegr oups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================
> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================
> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>

Change object all object onwer

I have a script like below to change all the object owner from "xxxxx"
to "dbo".
====================================
declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCHChange one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegroups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================
> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================
> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>

Friday, February 10, 2012

Change minimum database size from 3mb to 2mb

Hi
I have been using sql express so far with my FileManager database.
Since I migrated to SQL 2005 developer edition, I am unable to execute
sql script created from FileManager database before uninstalling sql
express.
Code:
USE [master]
GO
/****** Object: Database [FileManager] Script Date: 11/14/2007
19:58:28 ******/
CREATE DATABASE [FileManager] ON PRIMARY
( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
MAXSIZE = 2048GB , FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
..
..
..
Error:
Msg 1803, Level 16, State 1, Line 2
The CREATE DATABASE statement failed. The primary file must be at
least 3 MB to accommodate a copy of the model database.
How do i correct that.
Regards
Piotr Kolodziej
Hello,
You can not create database files less than your model database's database
files.
By default, model database has a 3MB in size mdf file and 1MB in size ldf
file. So you can not create a data file (mdf) less than 3MB in this
situation. If you want to
create a 2MB in size data file, then go and change your model databases mdf
data file size and set it 2MB. Then you'll be able to run your following
code successfully.
Ekrem nsoy
"Piotrekk" <Piotr.Kolodziej@.gmail.com> wrote in message
news:6ef9dfd8-9cee-4ba2-82aa-bf09176b79bb@.b36g2000hsa.googlegroups.com...
> Hi
> I have been using sql express so far with my FileManager database.
> Since I migrated to SQL 2005 developer edition, I am unable to execute
> sql script created from FileManager database before uninstalling sql
> express.
> Code:
> USE [master]
> GO
> /****** Object: Database [FileManager] Script Date: 11/14/2007
> 19:58:28 ******/
> CREATE DATABASE [FileManager] ON PRIMARY
> ( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE =
> UNLIMITED, FILEGROWTH = 1024KB )
> LOG ON
> ( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
> SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
> MAXSIZE = 2048GB , FILEGROWTH = 10%)
> COLLATE SQL_Latin1_General_CP1_CI_AS
> GO
> .
> .
> .
>
> Error:
> Msg 1803, Level 16, State 1, Line 2
> The CREATE DATABASE statement failed. The primary file must be at
> least 3 MB to accommodate a copy of the model database.
>
> How do i correct that.
> Regards
> Piotr Kolodziej

Change minimum database size from 3mb to 2mb

Hi
I have been using sql express so far with my FileManager database.
Since I migrated to SQL 2005 developer edition, I am unable to execute
sql script created from FileManager database before uninstalling sql
express.
Code:
USE [master]
GO
/****** Object: Database [FileManager] Script Date: 11/14/2007
19:58:28 ******/
CREATE DATABASE [FileManager] ON PRIMARY
( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
MAXSIZE = 2048GB , FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
.
.
.
Error:
Msg 1803, Level 16, State 1, Line 2
The CREATE DATABASE statement failed. The primary file must be at
least 3 MB to accommodate a copy of the model database.
How do i correct that.
Regards
Piotr KolodziejThe error message tell you what the problem is. The model database determine
s the minimum database
size. The size of model in 2005 (data file) is 3MB, which is why you can't m
ake the new database
smaller. You could shrink model first, but I do not recommend that solution.
Amend your script
instead and make the new database a reasonable size.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Piotrekk" <Piotr.Kolodziej@.gmail.com> wrote in message
news:6ef9dfd8-9cee-4ba2-82aa-bf09176b79bb@.b36g2000hsa.googlegroups.com...
> Hi
> I have been using sql express so far with my FileManager database.
> Since I migrated to SQL 2005 developer edition, I am unable to execute
> sql script created from FileManager database before uninstalling sql
> express.
> Code:
> USE [master]
> GO
> /****** Object: Database [FileManager] Script Date: 11/14/2007
> 19:58:28 ******/
> CREATE DATABASE [FileManager] ON PRIMARY
> ( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE =
> UNLIMITED, FILEGROWTH = 1024KB )
> LOG ON
> ( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
> SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
> MAXSIZE = 2048GB , FILEGROWTH = 10%)
> COLLATE SQL_Latin1_General_CP1_CI_AS
> GO
> .
> .
> .
>
> Error:
> Msg 1803, Level 16, State 1, Line 2
> The CREATE DATABASE statement failed. The primary file must be at
> least 3 MB to accommodate a copy of the model database.
>
> How do i correct that.
> Regards
> Piotr Kolodziej|||Hello,
You can not create database files less than your model database's database
files.
By default, model database has a 3MB in size mdf file and 1MB in size ldf
file. So you can not create a data file (mdf) less than 3MB in this
situation. If you want to
create a 2MB in size data file, then go and change your model databases mdf
data file size and set it 2MB. Then you'll be able to run your following
code successfully.
Ekrem nsoy
"Piotrekk" <Piotr.Kolodziej@.gmail.com> wrote in message
news:6ef9dfd8-9cee-4ba2-82aa-bf09176b79bb@.b36g2000hsa.googlegroups.com...
> Hi
> I have been using sql express so far with my FileManager database.
> Since I migrated to SQL 2005 developer edition, I am unable to execute
> sql script created from FileManager database before uninstalling sql
> express.
> Code:
> USE [master]
> GO
> /****** Object: Database [FileManager] Script Date: 11/14/2007
> 19:58:28 ******/
> CREATE DATABASE [FileManager] ON PRIMARY
> ( NAME = N'FileManager', FILENAME = N'c:\Program Files\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\FileManager.mdf' , SIZE = 2048KB , MAXSIZE =
> UNLIMITED, FILEGROWTH = 1024KB )
> LOG ON
> ( NAME = N'FileManager_log', FILENAME = N'c:\Program Files\Microsoft
> SQL Server\MSSQL.1\MSSQL\DATA\FileManager_log.ldf' , SIZE = 1024KB ,
> MAXSIZE = 2048GB , FILEGROWTH = 10%)
> COLLATE SQL_Latin1_General_CP1_CI_AS
> GO
> .
> .
> .
>
> Error:
> Msg 1803, Level 16, State 1, Line 2
> The CREATE DATABASE statement failed. The primary file must be at
> least 3 MB to accommodate a copy of the model database.
>
> How do i correct that.
> Regards
> Piotr Kolodziej

Change Logical Name in Script

I'm trying to restore about 70 databases onto a new SQL server and
wanted to script the creation and restore. I've done the creation with
no problems, but on the restore, the logical names (of the original
data) are all over the place and were historically wrong.

So, when I use the script below... I've had to work out the Logical
name for the data and the log file and alter the script accordingly.

Creation
----

Create Database MyDatabase ON (NAME = MyDatabase_data, FileName =
'D:\Database\MSSQL\Data\MyDatabase.mdf') LOG ON (NAME = MyDatabase_log,
FileName = 'D:\Database\MSSQL\Data\MyDatabase.ldf') COLLATE
SQL_Latin1_General_CP1_CI_AS

Restore
----

RESTORE FILELISTONLY
from disk =
'D:\Database\MSSQL\BACKUP\2006-08-07\MyDatabase_db_200608072100.BAK'

restore database MyDatabase
from disk =
'D:\Database\MSSQL\BACKUP\2006-08-07\MyDatabase_db_200608072100.BAK'
with REPLACE,
MOVE 'SomeOtherRubbish_Data' TO
'D:\Database\MSSQL\Data\MyDatabase.mdf',
MOVE 'SomeOtherRubbish_Log' TO
'D:\Database\MSSQL\Data\MyDatabase.ldf'
go

When I then look at the properties of the database, it shows the old
convention which I don't want.

So, even though I've been neat creating the database, it gets
overwritten with the odl rubbish name. How can I change the logical
name so that I can have a nice and neat naming convention ?

Oh, Yes I know I added the collation when creating the database, but
that's another thing that we need to address at some point.

Thanks in advanceRyan (ryanofford@.hotmail.com) writes:

Quote:

Originally Posted by

I'm trying to restore about 70 databases onto a new SQL server and
wanted to script the creation and restore. I've done the creation with
no problems, but on the restore, the logical names (of the original
data) are all over the place and were historically wrong.


If I understand this correctly, you first run CREATE DATABASE for a
database, and then RESTORE for the same database for you. I've bad news
for you: the script for CREATE DATABASE was in vein. RESTORE will create
the database if it does not exist. And if it exists, it will throw the
old one away.

Quote:

Originally Posted by

So, even though I've been neat creating the database, it gets
overwritten with the odl rubbish name. How can I change the logical
name so that I can have a nice and neat naming convention ?


ALTER DATBASE db MODIFY FILE oldname NAME = oldname, NEWNAME = newname

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks Erland. I'll give it a try. No major issue on not using the
create script, but thanks for the advice on that.

Ryan

Erland Sommarskog wrote:

Quote:

Originally Posted by

Ryan (ryanofford@.hotmail.com) writes:

Quote:

Originally Posted by

I'm trying to restore about 70 databases onto a new SQL server and
wanted to script the creation and restore. I've done the creation with
no problems, but on the restore, the logical names (of the original
data) are all over the place and were historically wrong.


>
If I understand this correctly, you first run CREATE DATABASE for a
database, and then RESTORE for the same database for you. I've bad news
for you: the script for CREATE DATABASE was in vein. RESTORE will create
the database if it does not exist. And if it exists, it will throw the
old one away.
>

Quote:

Originally Posted by

So, even though I've been neat creating the database, it gets
overwritten with the odl rubbish name. How can I change the logical
name so that I can have a nice and neat naming convention ?


>
ALTER DATBASE db MODIFY FILE oldname NAME = oldname, NEWNAME = newname
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx