Como agrego campos a mi actual tabla

  • Autor Autor blogers
  • Fecha de inicio Fecha de inicio
B

blogers

Pi
SEO
Hola compañeros venia a pedirles un favorsote como agrego estos campos a mi actual tabla

PHP:
-- Estructura de tabla para la tabla `mitabla`
--

CREATE TABLE IF NOT EXISTS `mitabla` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` int(11) DEFAULT NULL,
  `employer` varchar(100) DEFAULT NULL,
  `job_category` varchar(11) DEFAULT NULL,
  `region` varchar(50) DEFAULT NULL,
  `title` text,
  `message` text,
  `active` varchar(5) DEFAULT 'YES',
  `notification` varchar(5) DEFAULT 'NO',
  `contact_person` varchar(255) DEFAULT 'none',
  `places` text,
  `featured` tinyint(4) NOT NULL DEFAULT '0',
  `expires` int(11) NOT NULL DEFAULT '0',
  `zip` varchar(20) NOT NULL DEFAULT '',
  `job_type` tinyint(4) NOT NULL DEFAULT '2',
  `featured_expires` int(11) NOT NULL DEFAULT '0',
  `salary` varchar(150) NOT NULL DEFAULT '0',
  `date_available` varchar(50) NOT NULL DEFAULT '',
  `more_fields` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `employer` (`employer`),
  KEY `featured` (`featured`),
  KEY `expires` (`expires`),
  KEY `featured_expires` (`featured_expires`),
  KEY `job_category` (`job_category`),
  KEY `active` (`active`),
  KEY `date` (`date`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
 
Hola compañeros venia a pedirles un favorsote como agrego estos campos a mi actual tabla

PHP:
-- Estructura de tabla para la tabla `mitabla`
--

CREATE TABLE IF NOT EXISTS `mitabla` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` int(11) DEFAULT NULL,
  `employer` varchar(100) DEFAULT NULL,
  `job_category` varchar(11) DEFAULT NULL,
  `region` varchar(50) DEFAULT NULL,
  `title` text,
  `message` text,
  `active` varchar(5) DEFAULT 'YES',
  `notification` varchar(5) DEFAULT 'NO',
  `contact_person` varchar(255) DEFAULT 'none',
  `places` text,
  `featured` tinyint(4) NOT NULL DEFAULT '0',
  `expires` int(11) NOT NULL DEFAULT '0',
  `zip` varchar(20) NOT NULL DEFAULT '',
  `job_type` tinyint(4) NOT NULL DEFAULT '2',
  `featured_expires` int(11) NOT NULL DEFAULT '0',
  `salary` varchar(150) NOT NULL DEFAULT '0',
  `date_available` varchar(50) NOT NULL DEFAULT '',
  `more_fields` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `employer` (`employer`),
  KEY `featured` (`featured`),
  KEY `expires` (`expires`),
  KEY `featured_expires` (`featured_expires`),
  KEY `job_category` (`job_category`),
  KEY `active` (`active`),
  KEY `date` (`date`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

??? ya tienes una tabla llamada mitabla y quieres agregar estos campos?... no entiendo...
 
Asi esta actualemente

PHP:
CREATE TABLE IF NOT EXISTS `mitabla` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `message` text NOT NULL,
  `link` text NOT NULL,
  `link2` text,
  `source_name` varchar(255) NOT NULL,
  `query` varchar(25) NOT NULL,
  `location` varchar(255) NOT NULL,
  `serial` varchar(255) NOT NULL,
  `date` int(10) NOT NULL DEFAULT '1362092400',
  `company` tinytext NOT NULL,
  `city` tinytext NOT NULL,
  `state` tinytext NOT NULL,
  `formattedLocation` tinytext NOT NULL,
  `latitude` tinytext NOT NULL,
  `longitude` tinytext NOT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=50795 ;


---------- Post agregado el 20-may-2014 hora: 03:01 ----------

Pero no se pued ehacer con sentencia por que si son como 30 tablas
solo edita la tabla agregando los campos necesarios... sin agregar otro primario
 
Asi esta actualemente

PHP:
CREATE TABLE IF NOT EXISTS `mitabla` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `message` text NOT NULL,
  `link` text NOT NULL,
  `link2` text,
  `source_name` varchar(255) NOT NULL,
  `query` varchar(25) NOT NULL,
  `location` varchar(255) NOT NULL,
  `serial` varchar(255) NOT NULL,
  `date` int(10) NOT NULL DEFAULT '1362092400',
  `company` tinytext NOT NULL,
  `city` tinytext NOT NULL,
  `state` tinytext NOT NULL,
  `formattedLocation` tinytext NOT NULL,
  `latitude` tinytext NOT NULL,
  `longitude` tinytext NOT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=50795 ;


---------- Post agregado el 20-may-2014 hora: 03:01 ----------

Pero no se pued ehacer con sentencia por que si son como 30 tablas

hacelo solo con una y luego copia el codigo mysql que genera phpmyadmin y lo usas en todas las demas tablas. agrega todas las columnas necesarias y ejecutalo, y phpmyadmin te mostrara el codigo generado.
 
ASI

PHP:
ALTER TABLE bot1.`mitabla` 
ADD `id` int(11) NOT NULL AUTO_INCREMENT,
ADD `date` int(11) DEFAULT NULL,
ADD  `employer` varchar(100) DEFAULT NULL,
ADD  `job_category` varchar(11) DEFAULT NULL,
ADD `region` varchar(50) DEFAULT NULL,
ADD  `title` text,
ADD  `message` text,
ADD  `active` varchar(5) DEFAULT 'YES',
ADD  `notification` varchar(5) DEFAULT 'NO',
ADD  `contact_person` varchar(255) DEFAULT 'none',
ADD  `places` text,
ADD  `featured` tinyint(4) NOT NULL DEFAULT '0',
ADD  `expires` int(11) NOT NULL DEFAULT '0',
ADD  `zip` varchar(20) NOT NULL DEFAULT '',
ADD `job_type` tinyint(4) NOT NULL DEFAULT '2',
ADD  `featured_expires` int(11) NOT NULL DEFAULT '0',
ADD  `salary` varchar(150) NOT NULL DEFAULT '0',
ADD  `date_available` varchar(50) NOT NULL DEFAULT '',
ADD  `more_fields` text NOT NULL,
  
  KEY `employer` (`employer`),
  KEY `featured` (`featured`),
  KEY `expires` (`expires`),
  KEY `featured_expires` (`featured_expires`),
  KEY `job_category` (`job_category`),
  KEY `active` (`active`),
  KEY `date` (`date`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
hacelo solo con una y luego copia el codigo mysql que genera phpmyadmin y lo usas en todas las demas tablas. agrega todas las columnas necesarias y ejecutalo, y phpmyadmin te mostrara el codigo generado.
 
ASI

PHP:
ALTER TABLE bot1.`mitabla` 
ADD `id` int(11) NOT NULL AUTO_INCREMENT,
ADD `date` int(11) DEFAULT NULL,
ADD  `employer` varchar(100) DEFAULT NULL,
ADD  `job_category` varchar(11) DEFAULT NULL,
ADD `region` varchar(50) DEFAULT NULL,
ADD  `title` text,
ADD  `message` text,
ADD  `active` varchar(5) DEFAULT 'YES',
ADD  `notification` varchar(5) DEFAULT 'NO',
ADD  `contact_person` varchar(255) DEFAULT 'none',
ADD  `places` text,
ADD  `featured` tinyint(4) NOT NULL DEFAULT '0',
ADD  `expires` int(11) NOT NULL DEFAULT '0',
ADD  `zip` varchar(20) NOT NULL DEFAULT '',
ADD `job_type` tinyint(4) NOT NULL DEFAULT '2',
ADD  `featured_expires` int(11) NOT NULL DEFAULT '0',
ADD  `salary` varchar(150) NOT NULL DEFAULT '0',
ADD  `date_available` varchar(50) NOT NULL DEFAULT '',
ADD  `more_fields` text NOT NULL,
  
  KEY `employer` (`employer`),
  KEY `featured` (`featured`),
  KEY `expires` (`expires`),
  KEY `featured_expires` (`featured_expires`),
  KEY `job_category` (`job_category`),
  KEY `active` (`active`),
  KEY `date` (`date`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

sisi altertable es para eso, alterar la tabla (eliminando, agregando o modificando campos)
 
Atrás
Arriba