标签:
mysql copy表或表数据常用的语句整理汇总.
假如我们有以下这样一个表:
id username password
-----------------------------------
1 admin *************
2 sameer *************
3 stewart *************
#SQL
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(6) unsigned NOT NULL auto_increment,
`username` varchar(50) NOT NULL default ‘‘,
`password` varchar(100) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
CREATE TABLE newadmin LIKE admin
CREATE TABLE newadmin AS
(
SELECT * FROM admin
)
CREATE TABLE newadmin LIKE admin;
INSERT INTO newadmin SELECT * FROM admin;
CREATE TABLE newadmin LIKE shop.admin;
CREATE TABLE newshop.newadmin LIKE shop.admin;
CREATE TABLE newadmin AS
(
SELECT username, password FROM admin
)
CREATE TABLE newadmin AS
(
SELECT id, username AS uname, password AS pass FROM admin
)
CREATE TABLE newadmin AS
(
SELECT * FROM admin WHERE LEFT(username,1) = ‘s‘
)
CREATE TABLE newadmin
(
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY
)
AS
(
SELECT * FROM admin
)
CREATE TABLE 新表 SELECT * FROM 旧表
CREATE TABLE 新表
SELECT * FROM 旧表 WHERE 1=2
即:让WHERE条件不成立.
create table 新表(字段1,字段2,,,) SELECT 字段1,字段2... FROM 旧表
标签:
原文地址:http://www.cnblogs.com/stevin-john/p/5439754.html