0

我在下面有这个执行一些 mysql 查询的 php 代码,基于一些逻辑,我想构建可以从 sql server 导入的普通 SQL 代码。

我怎样才能做到这一点?

谢谢你的帮助!!!

mysql_query("CREATE DATABASE IF NOT EXISTS `".$mysql_db."`"); --I don't know how with this line

$q = "SHOW FULL TABLES IN ".$mysql_db;
$q = mysql_query($q);

if($tc==0)  --//don't worry about $tc
{
  mysql_query("
  CREATE TABLE IF NOT EXISTS `tdagg` ( --And i don't know how with this
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Pais` varchar(255) NOT NULL,
  `HackingInt` int(11) NOT NULL,
  `Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, --timestamp can be replace by datetime
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; --//I don't understand this line
  ");
  mysql_query("
  CREATE TABLE IF NOT EXISTS `tdagg_accs` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Account` varchar(11) NOT NULL,
  `IP` varchar(30) NOT NULL,
  `Hacker` varchar(40) NOT NULL,
  `Fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `Pais` varchar(255) NOT NULL DEFAULT 'Undefined',
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  ");
}else
{
  mysql_query("
  ALTER TABLE `tdagg_accs` ADD `Pais` varchar(255) NOT NULL DEFAULT 'Undefined'
  ");
}
4

1 回答 1

0
IF EXISTS(select * from sys.databases where name='your_dbname')
DROP DATABASE your_dbname

Go

Create DATABASE your_dbname

go

IF EXISTS(select * from sys.tables where name='tdagg')
DROP TABLE tdagg

Go
USE your_dbname
Go
CREATE TABLE tdagg ( 
  ID int NOT NULL identity PRIMARY KEY,
  Pais varchar(255) NOT NULL,
  HackingInt int NOT NULL,
  Date timestamp NOT NULL
  )

同样的方式你可以为其余的表做

于 2012-10-10T07:24:26.870 回答