VistaDB 6
VistaDB / Developer's Guide / How To Perform Common Tasks / Create a New Database in Code / How To Create a new database using SQL
In This Topic
    How To Create a new database using SQL
    In This Topic

    Creating a database in SQL code is a little different. You can use the Data Builder to create a new database, or you can do it direct from code.

    The Create Database command must be executed before opening a connection

    The create database command is the only SQL command that does not require a valid connection to exist before it can be run. You can test this by opening the Data Builder without a database and typing in a create database command in the query window. The database will be created without having a valid connection.

    You still have to create the VistaDBConnection object, but you leave the database field blank.

    This will create a new database in your current path from SQL Code. This can be very useful when an application is first installed to build the database from scratch in code rather than relying on an installed starter database.


    Create a Database in SQL Example
    Copy Code
       using( VistaDB.Provider.VistaDBConnection connection = new VistaDB.Provider.VistaDBConnection() )
          using( VistaDB.Provider.VistaDBCommand command = new VistaDB.Provider.VistaDBCommand() )
             command.Connection = connection;
             command.CommandText = "CREATE DATABASE 'NEWDB.vdb6', PAGE SIZE 4, LCID 1033, CASE SENSITIVE FALSE;";


    If a connection is currently open on the object when create database is called it will closed by the engine.

    The extension .vdb6 is automatically added to the database name by default if no extension is included. If a custom extension is included it will be used (if your edition supports custom extensions).



    Will create a NEWDB.vdb6 database in the current path.
    See Also