Results 1 to 6 of 6

Thread: [RESOLVED] Create Tables

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Resolved [RESOLVED] Create Tables

    Hi

    In the Below code tables are created in Master , whereas tables should be created in MyDatabase.

    Dim str As String
    Dim sql As String
    Dim str_use As String

    str = "CREATE DATABASE MyDatabase ON PRIMARY " & _
    "(NAME = MyDatabase_Data, " & _
    " FILENAME = 'E:\T01-02.mdf', " & _
    " SIZE = 2MB, " & _
    " MAXSIZE = 10MB, " & _
    " FILEGROWTH = 10%) " & _
    " LOG ON " & _
    "(NAME = MyDatabase_Log, " & _
    " FILENAME = 'E:\T01-02.ldf', " & _
    " SIZE = 1MB, " & _
    " MAXSIZE = 5MB, " & _
    " FILEGROWTH = 10%) "
    conFind.Execute (str)

    str_use = "Use MyDatabase"
    conFind.Execute (str_use)

    sql = "Create table VType(" & _
    "[vtype] [nvarchar](20)" & _
    "Primary Key([VType]))"
    conFind.Execute (sql)

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Create Tables

    Thread moved to the 'Database Development' forum - which is where you should always post Database/SQL specific questions (while Databases and SQL can be used in VB, they are certainly not specific to VB)

  3. #3
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Create Tables

    Try
    Code:
    sql = "Create table MyDatabase.VType(" & _
           "[vtype] [nvarchar](20)" & _
           "Primary Key([VType]))"
    conFind.Execute (sql)
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Re: Create Tables

    Hi

    It is giving error "Specified Schema does not exists or you don't have permission to use it ".
    MyDatabase exists

    Thanks

  5. #5
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: [RESOLVED] Create Tables

    In my case I use dbo as schema, try : MyDatabase.dbo.VType
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Create Tables

    dbo is the "DataBaseOwner" ... not the schema... the full format is Schema.Owner.Object... at any rate... the reason it didn't work originally was because it was using the original connection which was tied to the master database... once the database is created, close the connection, and re-open it, this time using the new database as the schema... then your create tables will work as expected.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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