Creating Database and Table

winsonlee
06-14-2002, 02:36 AM
anyone here knows how i can create database and table through coding ??

Road Runner
06-14-2002, 02:45 AM
Well you can create a database and a table in a database using the CREATE Keyword in SQL. An example of this can be found here (http://www.w3schools.com/sql/sql_create.asp) at http://www.w3schools.com

Hope it helps
Shane:)

Nattyboy
06-14-2002, 03:59 AM
Well just learn how to Create Database & tables from the Query Analyzer and for the Scripts "how to" refer the Books Online. if you have installed SQL in ur machine u can refer to that. after trying the sample thru query analyzer just copy that code and put in a Variable like


' Open up the Connection to the Database
strSql = "Create Table ......."
' Execute Code in strSql
rs.Open strSql, Con, 0, 1
' Now the table should be created in the database which u mentioned


For creating the Database from ASP page u need to first connect to the "master" database in the SQL Server and then Create the Database using the above same proc then connect to ur database and create the table in it :) .. very simple if u know understand what am saying

try n reply back..

winsonlee
06-16-2002, 09:07 PM
Is there anyway i can create a Database and Tables automatically at the 1st of every month ??? For your information, currently i am using SQL Server 7.0 as my database.

winsonlee
06-17-2002, 09:39 AM
For your information i would like to create a database and multiple table using asp and the database and tables need to be created every beginning of the month which is exactly on the 1st of everymonth. Is there anyway i can automatically execute the asp script at the server side so that the database can be created or is there any similar way i can do that ????

Thinker
06-17-2002, 06:05 PM
I believe the only way to get the script to run in an ASP page is if
it is requested from the web server. It might be possible to have
some process on the server to request the page directly, maybe
even as localhost. The alternative is to have code in the page
that checks the date, and if the new tables for that month don't
exist, it does the create. This code would add some overhead,
but unless you have thousands of hits a day, you probably won't
notice it.

winsonlee
06-19-2002, 11:09 AM
Do you have sample code to know if the database and table is created for that particular month ???

Thinker
06-19-2002, 12:43 PM
If you are actually creating a new .mdb file each month, it should
be a simple matter of using some file access method (like Dir()) to
determine if the .mdb exists. If just looking for a new set of
tables in an existing .mdb, I would first try using the ADO
OpenSchema method to look for the tables.

winsonlee
06-19-2002, 10:06 PM
But if i am using SQL Server 7.0, how can i check if the database exist ???

brillo
06-19-2002, 11:33 PM
I know Sql has a system table with records of every table in the database. I do not remember which table it is but you should be able to find it.

Once you know the system table just "Select Count(*) From [system table] where [column name] = [your monthly table]". The returned results should be 0 or 1 (1 meaning one record found).

On a more business perspective...
My clients often think by requesting monthly, quarterly and/or yearly tables is the way to go. I quickly let them know multiple reports will need to be created and multiple tables are not really neccessary. A report can give them all the aggregate levels of data from one table.

Thinker
06-20-2002, 04:49 PM
Sorry, I missed that you said SQL Server. Brillo is correct, you can
query the sysdatabases table in the master database. You can
use the sp_helpdb to get a recordset with all databases.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum