Results 1 to 2 of 2

Thread: How to do this in SQL???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Netherlands Antilles
    Posts
    66
    Hi Anyone,

    I have gotten this to work with an Access File.
    does anyone know how to do this with SQL Server 7.0?

    Let me know.
    Thanks,
    EL.

    Public DbFile As Database
    Public RstFile As Recordset
    Public FileName As String
    Public TblFile As TableDef
    Public IdxFile As Index
    Public FLD As Field
    Public WrkDefault As Workspace
    Public DbsNew As Database

    Public Sub CreateDatabase()
    FileName = App.Path & "\database.mdb"
    If Dir(FileName) <> "" Then
    'open database file
    Set DbsNew = OpenDatabase(FileName)
    Set RstFile = DbFile.OpenRecordset("Recordset")
    Else
    Set WrkDefault = DBEngine.Workspaces(0)
    Set DbsNew = CreateDatabase(FileName, dbLangGeneral)
    Set TblFile = DbFile.CreateTableDef("Recordset") ' create recordset
    With TblFile
    .Fields.Append .CreateField("FieldName", dbText, 10)
    DbFile.TableDefs.Append TblFile
    End With
    Set IdxFile = TblFile.CreateIndex("IdxFile")
    Set FLD = IdxFile.CreateField("Fieldname")
    With IdxFile
    .Primary = True
    .Unique = True
    .Required = True
    End With
    IdxFile.Fields.Append FLD
    TblFile.Indexes.Append IdxFile
    DbFile.Close
    End If
    End Sub

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    60
    elpower,

    I don't think that DAO is going to cut it to create a database on a SQL Server. I've never actually created a database throught code, but here goes.

    Using an ADO command object, you can send a T-SQL statement to the server via ODBC or whichever provider you want to use. The following is from the SQL Server book online:

    CREATE DATABASE database_name
    [ ON [PRIMARY]
    [ <filespec> [,...n] ]
    [, <filegroup> [,...n] ]
    ]
    [ LOG ON { <filespec> [,...n]} ]
    [ FOR LOAD | FOR ATTACH ]

    <filespec> ::=

    ( [ NAME = logical_file_name, ]
    FILENAME = 'os_file_name'
    [, SIZE = size]
    [, MAXSIZE = { max_size | UNLIMITED } ]
    [, FILEGROWTH = growth_increment] ) [,...n]

    <filegroup> ::=

    FILEGROUP filegroup_name <filespec> [,...n]

    Exactly how this works, I'll be able to tell you later on, but I don't have enough time to play with it at the moment, hope this helps.
    Barend
    JHB-SA

    Nothing is impossible, except skiing through a revolving door.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width