all groups > sql server programming > july 2007 >
You're in the

sql server programming

group:

SQL Server 2005 create table


SQL Server 2005 create table WRH
7/31/2007 8:11:50 PM
sql server programming:
Hello
I have a legacy VS C++ program which works well with SQL Server 2000,
creating
tables etc as required. The same program does not work with Server 2005
express,
eg CREATE TABLE fails. Is this a known issue with a fix or do I need to
rewrite
code?

Re: SQL Server 2005 create table Aaron Bertrand [SQL Server MVP]
7/31/2007 11:49:46 PM
Please be more specific. What do the phrases "does not work" and "fails"
mean? Do you get an error message? If so, what is it? What is the CREATE
TABLE statement you are attempting to run?

--
Aaron Bertrand
SQL Server MVP




[quoted text, click to view]

Re: SQL Server 2005 create table Aaron Bertrand [SQL Server MVP]
8/1/2007 12:00:00 AM
The C++ code to construct the CREATE TABLE statement does little to help
here. Can you have C++ print out the CREATE TABLE statement it eventually
tries to execute? And once again, can you explain what "will not create
tables" means? Do you get an error message? If so, WHAT IS IT? Think
about calling your doctor and simply saying "I don't feel good." Do you
think he will be able to diagnose over the phone, without getting any more
information?

--
Aaron Bertrand
SQL Server MVP




[quoted text, click to view]

Re: SQL Server 2005 create table WRH
8/1/2007 12:00:00 AM
I have this SQL string...

CREATE TABLE Inbox
(
Msg varchar(200)
Size varchar(200)
Subject varchar(200)
Frm varchar(200)
Date varchar(200)
Body text
Too text
Dbst varchar(200)
Cc text
Bcc text
)

The error message is Invalid object name 'Inbox'





[quoted text, click to view]

Re: SQL Server 2005 create table Aaron Bertrand [SQL Server MVP]
8/1/2007 12:00:00 AM
[quoted text, click to view]

This would not work in any version of SQL Server. It needs to be:

CREATE TABLE Inbox
(
Msg varchar(200),
Size varchar(200),
....etc.

You also should enclose column names in [brackets] if you are going to use
keywords like size and date.

A

Re: SQL Server 2005 create table WRH
8/1/2007 12:00:00 AM
Thanks again to all.
I put in the comma's and it worked fine!




[quoted text, click to view]

Re: SQL Server 2005 create table WRH
8/1/2007 12:00:00 AM
Yes. This code has worked very well for a number of years.
I am not knowledgeable about SQL, but I developed and
tested the code using SQL 2000.
In this string there are no comma's but there are CR/LF
after each parameter. Perhaps SQL 2000 accepted this
in lieu of commas.


CREATE TABLE Inbox
(
Msg varchar(200)
Size varchar(200)
Subject varchar(200)
Frm varchar(200)
Date varchar(200)
Body text
Too text
Dbst varchar(200)
Cc text
Bcc text
)




[quoted text, click to view]

Re: SQL Server 2005 create table Aaron Bertrand [SQL Server MVP]
8/1/2007 12:00:00 AM
I don't see how it could have, and I think you are mistaken. When I run
that code in Query Analyzer against SQL Server 2000 I get:

Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near 'Size'.

--
Aaron Bertrand
SQL Server MVP





[quoted text, click to view]

Re: SQL Server 2005 create table WRH
8/1/2007 12:00:00 AM
Thanks all!

I will try it immediately.

I will say however, that it has worked as is for several years
with SQL 2000.



[quoted text, click to view]

Re: SQL Server 2005 create table WRH
8/1/2007 12:18:50 AM
I have a class which connects to the data base ok
but will not create tables. All was ok in SQL 2000...


....
_ConnectionPtr m_pConnection;
....


sql = "CREATE TABLE ";
sql += TableName[tbl];
sql += "\r\n(\r\n";



nf = 10;

for(i=0;i<nf;i++)
{
sql += FieldName[i];


}//for i=0;i< nf


sql += ")\r\n";

This function returns FALSE when given the string sql



BOOL CADODatabase::Execute(LPCTSTR lpstrExec)
{
ASSERT(m_pConnection != NULL);
ASSERT(strcmp(lpstrExec, _T("")) != 0);
_variant_t vRecords;

m_nRecordsAffected = 0;

try
{
m_pConnection->CursorLocation = adUseClient;
m_pConnection->Execute(_bstr_t(lpstrExec), &vRecords, adExecuteNoRecords);
m_nRecordsAffected = vRecords.iVal;
return TRUE;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}



[quoted text, click to view]

Re: SQL Server 2005 create table ML
8/1/2007 4:56:01 AM
If you need help regarding C++, aks this question in a C++ newsgroup.

We need to see the actual query being passed to the server.


ML

---
Matija Lah, SQL Server MVP
Re: SQL Server 2005 create table ML
8/1/2007 6:32:05 AM
No commas.

Try this:

CREATE TABLE Inbox
(
Msg varchar(200)
,Size varchar(200)
,Subject varchar(200)
,Frm varchar(200)
,Date varchar(200)
,Body text
,Too text
,Dbst varchar(200)
,Cc text
,Bcc text
)


ML

---
Matija Lah, SQL Server MVP
Re: SQL Server 2005 create table ML
8/1/2007 6:48:02 AM
[quoted text, click to view]

Are you absolutely sure? How have you verified that?


ML

---
Matija Lah, SQL Server MVP
Re: SQL Server 2005 create table WRH
8/1/2007 10:46:27 AM
I could be mistaken. It is a large program and SQL routines
are only a small part of it. But SQL storage worked fine.
It may not have been SQL 2000 however...what was the standard
Microsoft SQL before 2000?

This code definitely worked on a Microsoft SQL server!



[quoted text, click to view]

Re: SQL Server 2005 create table WRH
8/1/2007 6:38:53 PM
How do you enter the string in the Query Analyzer?

In C++, the string contains CR LF, ie the characters \r\n

eg "CREATE TABLE Inbox (Msg varchar(200)\r\nSize varchar(200)\r\n..."

I can't be sure of the SQL version but I can be sure this code did work
ok.


[quoted text, click to view]

Re: SQL Server 2005 create table Gert-Jan Strik
8/1/2007 9:49:10 PM
The version before SQL Server 2000 is SQL Server 7.0, and it returns the
same error message:

Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near 'Size'.


Gert-Jan


[quoted text, click to view]
AddThis Social Bookmark Button