Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How to create a database from Command prompt


1 reply to this topic

shajilr

shajilr
  • Members
  • 11 posts

Posted 15 October 2002 - 12:59

Hi,
   I want to create a database from command promt during installation (Using isql / osql ). Could anyone help me on this. It would be of great help if any one can help with some examples.
Thanks,
Shajil

Xitch13

Xitch13
  • Members
  • 134 posts

Posted 15 October 2002 - 15:16

well I use a multi-tier step to accomplish this.  First I use the script to create the directories.  Then I call a batch file:
Code Sample

///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION: CreateDatabase():
//            
//  PURPOSE: This function will setup the database and log files
// for Digital and Analog Server setup.
///////////////////////////////////////////////////////////////////////////////
function CreateDatabase()

STRING szPath, Adb, Ddb, szMsg, szMsg1;
NUMBER DVD, nvExitCode, nExit,nSize;

begin

// Create MyDB database .mdf & .ldf files//
   

   
szPath = "E:\\MyDB";                                            
if ExistsDir(szPath) < 0 then
CreateDir(szPath);
if (CreateDir(szPath) < 0) then
MessageBox("E:\MyDB, directory was not created successfully.", SEVERE);
abort;
endif;
endif;

szPath = "D:\\MyDB";      
if ExistsDir (szPath) < 0 then
CreateDir (szPath);
if (CreateDir (szPath) < 0) then
MessageBox ("D:\MyDB, directory was not created successfully.", SEVERE);
abort;
endif;
endif;
   
   
   VarSave(SRCTARGETDIR);
   TARGETDIR = TARGETDIR + "\\ProductName Database";
   ChangeDirectory (TARGETDIR); // It is necessary to do a change directory before launch.
if(bIsWindows2000=TRUE) then
SdShowMsg("Creating and modifying MyDB database.", TRUE);
Enable(HOURGLASS);
_LaunchAppEx(TARGETDIR + "\\CreateDatabase.bat", "", WAIT,SW_HIDE,-1,nExit);
SdShowMsg("Creating and modifying  MyDB database.", FALSE);
Disable(HOURGLASS);
else
   SdShowMsg("Creating and modifying MyDB database.", TRUE);
   Enable(HOURGLASS);
LaunchAppAndWait(TARGETDIR + "\\CreateDatabase.bat", "", WAIT);
SdShowMsg("Creating and modifying MyDB database.", FALSE);
Disable(HOURGLASS);
endif;
   VarRestore (SRCTARGETDIR);


endif;




The batch file I call follows:
Code Sample
echo off
echo Creating MyDB database...
isql -E -n -i CreateMyDB.sql
echo Creating jobs...
isql -E -n -i CreateJobs.sql
echo Adding tables and stored procedures...
echo off
isql -E -n -m 20 -d MyDB -i ScriptName.sql
echo Adding domain data...
echo off
isql -E -n -m 20 -d MyDB -i InsertDomainRecords.sql
echo Finished creating MyDB database!


and then my sql scripts:
Code Sample
create database MyDB
on
(name = 'MyDB',
filename = 'e:\ProductName\MyDB.mdf',
size = 50,
maxsize = 5500,
filegrowth = 10)
log on
(name = 'MyDBLog',
filename = 'd:\ProductName\MyDB.ldf',
size = 500,
filegrowth = 10)
go

/* Set some database options */
exec sp_dboption 'MyDB', 'autoshrink', 'FALSE'
exec sp_dboption 'MyDB', 'trunc. log on chkpt.', 'FALSE'


Hope this helps.  Some of it is pretty specific to what I do, but it should give you an idea.
A caveat:  Since I only install or Server software on systems we design, I already know what the drive scheme looks like.  You'll probably need to be a littel more deterministic.
There is great chaos under heaven, and the situation is excellent. (Mao Tse Tung)