|
| Previous Thread |
|
|
8/10/2006 1:09:11 PM Re: Create table eror |
There is no CREATE TABLE IF NOT EXISTS statement in T-SQL.
You would need to use something along the lines of:
IF NOT EXISTS (select * from dbo.sysobjects
WHERE id = object_id('dbo.TableName')
AND OBJECTPROPERTY(id, 'IsUserTable') = 1)
CREATE TABLE dbo.TableName
(ColumnName varchar(50) not null,
etc......)
-Sue
On Thu, 10 Aug 2006 19:45:59 +0100, John
<yjdyhugo@d8hujsrfu> wrote:
|
|
|
|
|
8/10/2006 7:17:41 PM Re: Create table eror |
Yes that's T-SQL. T-SQL (Transact SQL) is SQL Server's
implementation or "flavor" of SQL.
-Sue
On Thu, 10 Aug 2006 21:04:35 +0100, John
<yjdyhugo@d8hujsrfu> wrote:
|
|
|
8/10/2006 7:45:59 PM Create table eror |
I am able to connect to a database set up on SQL windows 2003 under
IIS. However I get an error message when I try to create a table. I am
running from php.
I am sure I am doing something stupid but I can't see it or could it
be a permissions issue?
Error -
Connection to Database members Successful.
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near
the keyword 'IF'.
Code -
//create a table in that dbase
$sql ="CREATE TABLE IF NOT EXISTS $_SESSION[table_name]
(
firstname VARCHAR(20),
lastname VARCHAR(20),
username VARCHAR(20),
password VARCHAR(50),
group1 VARCHAR(20),
group2 VARCHAR(20),
group3 VARCHAR(20),
pchange VARCHAR(1),
email VARCHAR(100),
redirect VARCHAR(100),
verified VARCHAR(1),
last_login DATE
)";
$result = odbc_exec($connection,$sql) or die(odbc_errormsg());
Any ideas or places to look gratefully received.
John
|
|
|
8/10/2006 9:04:35 PM Re: Create table eror |
On Thu, 10 Aug 2006 13:09:11 -0600, Sue Hoegemeier
<Sue_H@nomail.please> wrote:
Thanks Sue
Would I be using T-SQL?
How can I find out?
I have never heard of that.
--
John
|
|
|
8/11/2006 7:01:18 AM Re: Create table eror |
On Fri, 11 Aug 2006 13:07:27 +0100, John <yjdyhugo@d8hujsrfu> wrote:
Sue already gave you the answer. In SQL Server's implementation of
SQL, "CREATE TABLE IF NOT EXISTS" is not legal syntax. Neither is
"DATE" a valid data type.
T-SQL (Transact SQL) defines what is legal syntax for SQL Server.
|
|
|
8/11/2006 9:31:28 AM Re: Create table eror |
On Thu, 10 Aug 2006 19:17:41 -0600, Sue Hoegemeier
<Sue_H@nomail.please> wrote:
Having had a quick look round TSQL seems to be an extension of SQL.
Are you saying that the code I used would not work on a server/SQL
implementation.
John
|
|
|
8/11/2006 1:07:27 PM Re: Create table eror |
On Fri, 11 Aug 2006 09:31:28 +0100, John <yjdyhugo@d8hujsrfu> wrote:
Further info
SQL seems to be objecting to
IF NOT EXISTS
&
last_login DATE
If I remove these then it runs through OK
Any ideas whu this is the case much appreciated.
John
|
|
|
8/12/2006 10:26:30 AM Re: Create table eror |
On Fri, 11 Aug 2006 07:01:18 -0700, Jack Jackson
<jacknospam@pebbleridge.com> wrote:
Sorry you are quite correct.
I thought T-SQL was an extension to SQL but it appears some things
have been taken out as well.
Is that the case?
Thanks for your help Sue and Jack, I think I am beginning to get the
picture now.
John
|
|
|
8/13/2006 3:26:03 PM Re: Create table eror |
It is an extension but it is also the "flavor" used by SQL
Server and impacts how some of the SQL and related standards
are implemented. So it's not just a matter of "additional
functionality" type of thing. Not all database vendors
implement all of the same ANSI SQL.And not everything
implemented by a database vendor is a SQL standard. You will
find plenty of variation in syntax, functionality among the
different database platforms.
-Sue
On Sat, 12 Aug 2006 10:26:30 +0100, John
<yjdyhugo@d8hujsrfu> wrote:
|
|
|
8/13/2006 11:09:50 PM Re: Create table eror |
On Sun, 13 Aug 2006 15:26:03 -0600, Sue Hoegemeier
<Sue_H@nomail.please> wrote:
Looks like I am going to have to wade through the mysql and spot the
differences as I go.
Thanks again for your help on this, I appreciate it.
--
John
|
|