473,757 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Create Table?

Is there a tool that can take an Access database and generate SQL
"CREATE TABLE" statements for all the tables in it?
Nov 13 '05 #1
3 3874
"blindsey" <bl******@dsicd i.com> wrote in message
news:f9******** *************** *@posting.googl e.com...
Is there a tool that can take an Access database and generate SQL
"CREATE TABLE" statements for all the tables in it?


There are several products that will reverse-engineer Jet (and other)
databases. MS Office Visio is one.
Nov 13 '05 #2
blindsey wrote:
Is there a tool that can take an Access database and generate SQL
"CREATE TABLE" statements for all the tables in it?


the code below is not finished/polished, but it's a start.
Watch for wrapping... for your purpose, just call while looping
tabledefs, e.g.

For each tdf in db.tabledefs
DoSomethingWith CreateSQLTable( tdf.name)
next

Can always modify it to take tdf as parameter.

Function CreateSQLTable( pstrTableName As String, Optional pfGrantAll As
Boolean = False)
On Error GoTo CreateSQLTables _Err
' Returns T-SQL create table statement for an Access table
' © T.Best 2000-2004
' You may distribute/modify this as part of an application.
' May need additional work to handle more field types and unique
indices

Dim e As Error, strErrMsg As String
Dim db As Database, tdf As TableDef, fld As Field, idx As Index
Dim strSQL As String
Dim strSQLTable As String
Dim strField As String
Dim strSQLCreateTab le As String
Set db = CodeDb()
strSQLTable = pstrTableName
Set tdf = db.TableDefs(ps trTableName)
' Build new
strSQL = ""
strSQL = strSQL & "create table " & strSQLTable & " (" & vbCrLf
For Each fld In tdf.Fields
strField = " [" & fld.Name & "] "
Select Case fld.Type
Case dbText
strField = strField & "varchar(" & fld.Size & ")"
Case dbDate
strField = strField & "datetime"
Case dbCurrency
strField = strField & "money"
Case dbLong
strField = strField & "int"
If fld.Attributes And dbAutoIncrField Then
strField = strField & " identity (1,1)"
End If
Case dbMemo
strField = strField & "text"
Case dbBoolean
strField = strField & "bit"
Case Else
Err.Raise 30001, , "Unknown field type ctrating table "
& strSQLTable & "." & fld.Name
End Select

If fld.Required Or fld.Attributes And dbAutoIncrField Then
strField = strField & " NOT NULL"
Else
strField = strField & " NULL"
End If
strSQL = strSQL & strField & "," & vbCrLf
Next
' strip off trailing "," & vbcrlf
strSQL = Left(strSQL, Len(strSQL) - 3)

strSQL = strSQL & ")"

strSQLCreateTab le = strSQL

' Primary keys
For Each idx In tdf.Indexes
If idx.Primary Then
strSQL = "alter table " & strSQLTable & " with nocheck add"
& vbCrLf
strSQL = strSQL & " constraint [aaPK_" & strSQLTable & "]
primary key nonclustered" & vbCrLf
strSQL = strSQL & " (" & vbCrLf
For Each fld In idx.Fields
strSQL = strSQL & " [" & fld.Name & "]" & vbCrLf
Next
strSQL = strSQL & " ) with fillfactor = 90"
End If ' is PK
Next

strSQLCreateTab le = strSQLCreateTab le & vbCrLf & strSQL

' other indices
For Each idx In tdf.Indexes
If Not idx.Primary Then
' need a bit of work here to determine unique indices
strSQL = "create index " & idx.Name & " on " & strSQLTable
& "("
For Each fld In idx.Fields
strSQL = strSQL & "[" & fld.Name & "],"
Next
' strip trailing ",
strSQL = Left$(strSQL, Len(strSQL) - 1)
strSQL = strSQL & ") with fillfactor=90"
strSQLCreateTab le = strSQLCreateTab le & vbCrLf & strSQL

End If ' not PK

Next idx

' grant permissions
If pfGrantAll Then
strSQL = "grant select,insert,u pdate,delete on " & strSQLTable
& " to public"
strSQLCreateTab le = strSQLCreateTab le & vbCrLf & strSQL
End If

CreateSQLTable = strSQLCreateTab le
CreateSQLTables _Exit:
On Error Resume Next
Set idx = Nothing
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Function
CreateSQLTables _Err:
Select Case Err
Case 3146 ' ODBC
For Each e In DBEngine.Errors
strErrMsg = strErrMsg & "#ODBC Error " & e.number & " -
" & e.Description & vbCr
Next
MsgBox strErrMsg, vbExclamation, "Error " & Err.number & "
in Import2SQL()"
Case Else
MsgBox Err.Description , 16, "Error #" & Err & " In
CreateSQLTables ()"
End Select
Resume CreateSQLTables _Exit
Resume
End Function
--
Pretentious? Moi?
Nov 13 '05 #3
bl******@dsicdi .com (blindsey) wrote in message news:<f9******* *************** **@posting.goog le.com>...
Is there a tool that can take an Access database and generate SQL
"CREATE TABLE" statements for all the tables in it?


Hi!

There's the possible way how to do what you need in CASE Studio 2.

http://www.casestudio.com

You will have to do the following steps: reverse engineer an Access
database, convert it into another database, e.g. Oracle (I do not know
what database you need to generate the SQL script for) and then you
can generate SQL script automatically.

Feel free to test it in the demo version which is for free on:
http://www.casestudio.com/enu/download.aspx

Regards,

Vladka Sikorova
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3599
by: Andrew | last post by:
I have a problem creating mySQL tables with PHP. I am making an app where a user can create a project. Pressing "submit" on proj_form.php goes to proj_add.php where a couple of things happen. The project's meta information is put into a project table, mysql_insert_id() gets the $proj_ID, and a table named that $proj_ID is created to hold all of that project's tasks. Here is my code to create the table for a project's tasks: // 2)...
0
1162
by: Morten Gulbrandsen | last post by:
USE company; DROP TABLE IF EXISTS EMPLOYEE; CREATE TABLE EMPLOYEE ( # PK SSN CHAR(9) NOT NULL, # FK SUPERSSN CHAR(9), DNO INT NOT NULL DEFAULT 1, CONSTRAINT EMPPK
4
4437
by: Michael Jackson | last post by:
I have a stored procedure to create a table. In my program I want the user to name the table to be created, therefore I pass a parameter to the SP for the table name. I cannot get it to work. It creates a table called "@NewTableName". Any ideas? CREATE PROCEDURE dbo.sp_FFProduction_CreateTable (
2
5147
by: Karen Sullivan | last post by:
Hi, all. I'm fairly new to SQL, and I have been trying to create a table from a text file. I have been looking at this for days, and can't find the problem. I get a syntax error " Line 55: Incorrect syntax near 'DateUpdated'." Here is the query. Any suggestions would be appreciated, as I am trying to learn and improve. Use ACH go if exists (select * from dbo.sysobjects where id =
6
12295
by: Bruce | last post by:
I want to create a new table based on an existing table, but I don't want the tables to have any enforced relationship. Is this possible without having to do a CREATE TABLE and an INSERT? create table customer_Temp as (select credit_Card_number, personal_id_number from customer) DATA INITIALLY DEFERRED REFRESH deferred; refresh table customer_temp;
2
13926
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks ( weekstart datetime not null primary key, weekend datetime not null )
6
7713
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP which reads and drops the same temporary table. My users are not able to create dbo tables (eg dbo.tblTest), but are permitted to create tables under their own user (eg MyUser.tblTest). I have found that I can achieve my aim by using code like...
24
2890
by: Dan2kx | last post by:
Hello to all that read and thank you to all that post Background: I have been tasked to create a holiday database for the employees in my lab, (so expect many more posts) im stuck at the first hurdle, i want to have a table with emplyee details, and to create a new table for each employee to include holiday dates and ammounts etc, so i need a create table query to creat a brand new (unrelated query) for each employee. in the "staff"...
3
4592
by: SteveP26 | last post by:
Hi guys, I keep getting this error message (below) when I try to run the sql query for my database Heres the code, but the error message only applies to the LAST table (SalesCopy), I have no clue how its any different than the others. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
2
3395
jbt007
by: jbt007 | last post by:
All, Access 2003 - WinXP I thought this would be a no brainer, but it seems to be a perplexing problem. I have a simple table I use for importing several text reports, use VBA to run through the report to move data into tables. The temp table stays in access (tblTxtRpt), until the next report is imported, I then use SQL to DROP TABLE and CREATE TABLE to recreate it. This is because the table has an autonumber field that numbers the text...
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.