mysql copy表或表數據經常使用的語句整理彙總.mysql
假如咱們有如下這樣一個表:sql
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 舊錶