crear tabla mysql

Post Reply
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

crear tabla mysql

Post by artu01 »

Amigos del Foro:
No me crea la Bd, cual es el error

Code: Select all

  
  cCad := "Provider=SQLOLEDB;"
  cCad += "Server=PYSASERVER;"
  cCad += "Database=PysaBD;Uid=sa;Pwd=Pysa123456;"
  TRY
    oCon := CreateObject( "ADODB.Connection" )
  CATCH oError
     MsgStop( oError:Description )
  END
   TRY
     oCon:Open( cCad )
   CATCH oErr
     MsgInfo( "Could not open Connection to Database " )
     RETURN(.F.)
   END TRY

   cSql:="CREATE TABLE IF NOT EXISTS cabguit AS (SELECT * FROM cabguia)"

   Try
      oCon:Execute( cSQL )
   Catch
      MsgInfo( "Table Create BIN Failed" )
   End try

 
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: crear tabla mysql

Post by nageswaragunupudi »

Title of this topic says "MySql".
But you are trying to connect to Microsoft SQL Server. (MSSQL).

This is the correct connection string to be used to connect to MSSQL (not MySql)

Code: Select all

cCad := "Provider=SQLOLEDB;Data Source=PYSASERVER;Initial Catalog=PysaBD;User ID=SA;Password=Pysa123456;"
 
Regards

G. N. Rao.
Hyderabad, India
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: crear tabla mssql

Post by artu01 »

Mr. Rao:
You have right is MSSQL, not MySQL , typing error
its ok with the connection chain
selects, inserts, deletes do without problem
but i cant créate table
it got this error

Error BASE/1004 Message not found: LOGICAL:EXEC


Gente:

Estoy migrando mis tablas de dbf a sql, logro conectarme, hacer consultas, pero necesito crear tablas, es ahi donde no puedo
sale el msje de arriba

Code: Select all


  xPROVIDER := "SQLOLEDB"                  
  xSOURCE   := "PYSASERVER"                
  xCATALOG  := "PysaBD"                    
  xUSERID   := "sa"
  xPASSWORD := "Pysa123456"
  xConnect  := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD

  TRY
    oCon1 := CreateObject( "ADODB.Connection" )
    oCon1:Open( xConnect )
  CATCH oError
     MsgStop( oError:Description )
  END
// first option not run
   cSQL := "CREATE TABLE Bin"
   cSQL += "( "
   cSQL += "[BIN]       char(50) NOT NULL, "
   cSQL += "CONSTRAINT PK_BIN PRIMARY KEY ( BIN )"
   cSQL += " )"

   // second option also not run
   //cSql:="CREATE TABLE IF NOT EXISTS regtempo AS (SELECT * FROM cabguia)" 

   Try
      oCon1:Execute( cSQL )
   Catch
      MsgInfo( "Table Create BIN Failed" )
   End try


 
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: crear tabla mysql

Post by nageswaragunupudi »

MySql syntax does not always work in MSSql.

For example, CREATE ..IF NOT EXISTS .. does not work in MsSql

Please study MSSQL syntax
Suggest
http://www.w3schools.com
Regards

G. N. Rao.
Hyderabad, India
csincuir
Posts: 305
Joined: Sat Feb 03, 2007 6:36 am
Location: Guatemala
Contact:

Re: crear tabla mysql

Post by csincuir »

Artu, prueba con esta instrucción a ver si te crea la tabla (funciona tanto para MySQL como MSSql)

CREATE TABLE tablaprueba
(
clave VARCHAR(7) NOT NULL,
hechopor VARCHAR(60) NOT NULL,
valorint INT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (clave)
);

Saludos cordiales,

Carlos.
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: crear tabla mysql

Post by artu01 »

nageswaragunupudi wrote:Please study MSSQL syntax
Thank mr. rao, i shall do so
csincuir wrote:CREATE TABLE tablaprueba( clave VARCHAR(7) NOT NULL, hechopor VARCHAR(60) NOT NULL, valorint INT(1) NOT NULL DEFAULT 1, PRIMARY KEY (clave) );
Gracias csincuir, así me funciono

Code: Select all

cSQL := "CREATE TABLE #prueba"
cSQL += "("
cSQL += "clave VARCHAR(7) NOT NULL,"
cSQL += "hechopor VARCHAR(60) NOT NULL,"
cSQL += "valor INT NOT NULL DEFAULT 1"
cSQL += ")"
 
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
Post Reply