t-sql to create table

  • Thread starter Thread starter tobbe
  • Start date Start date
T

tobbe

Hi

How do I create a table in access whit a t-sql script? Im accessing the
database from a webpage and wants to create a table on the fly.
I have tried the following:

strSql = " CREATE TABLE language (pkid COUNTER not null, name Text(50)) "
objAdo.ExecQuery (strSql)

But it does not work.

Best Regards
Tobbe
 
probably you dont have enough permissions to create table? what error
message you get?
in case you use SQL server it should actually be:

"CREATE TABLE language (pkid int not null, name nvarchar(50))"
 
Thanks for your answer!

Thats the problem, im not using SQL Server i need to create the table in the
access database. The error i get is something like (have swedish access)
"Invalid syntax in create table". So im guessing that its possible to create
a table in Access through t-sql. The question is how dos the syntax look
like!? Havnt been able to find any help googling or altavistin ;)
 
tobbe said:
Thanks for your answer!

Thats the problem, im not using SQL Server i need to create the table in the
access database. The error i get is something like (have swedish access)
"Invalid syntax in create table". So im guessing that its possible to create
a table in Access through t-sql. The question is how dos the syntax look
like!? Havnt been able to find any help googling or altavistin ;)

Hi,
t-sql (transact-sql) is used only in SQL Server (MS or Sybase)
although ms access sql is similar. The access online help has some
examples of using Microsoft Jet SQL to create tables and indexes. For
example:

This example creates a new table called MyTable with two text fields,
a Date/Time field, and a unique index made up of all three fields.

Sub CreateTableX2()
Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.

Set dbs = OpenDatabase("Northwind.mdb")

' Create a table with three fields and a unique
' index made up of all three fields.

dbs.Execute "CREATE TABLE MyTable " _
& "(FirstName CHAR, LastName CHAR, " _
& "DateOfBirth DATETIME, " _
& "CONSTRAINT MyTableConstraint UNIQUE " _
& "(FirstName, LastName, DateOfBirth));"
dbs.Close
End Sub

hth,
Scott
 
Back
Top