Page 1 of 1

crear tabla mysql

Posted: Thu Feb 21, 2019 12:02 am
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

 

Re: crear tabla mysql

Posted: Thu Feb 21, 2019 7:09 am
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;"
 

Re: crear tabla mssql

Posted: Fri Feb 22, 2019 12:54 am
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


 

Re: crear tabla mysql

Posted: Fri Feb 22, 2019 2:46 am
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

Re: crear tabla mysql

Posted: Fri Feb 22, 2019 12:07 pm
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.

Re: crear tabla mysql

Posted: Sat Feb 23, 2019 12:39 am
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 += ")"