如何复制、克隆或复制数据、结构、,并将MySQL表的索引转换为新表?
这是我到目前为止发现的。
这将复制数据和结构,但不包括指数:
create table {new_table} select * from {old_table};
这将复制结构和索引,但不包括数据:
create table {new_table} like {old_table};
如何复制、克隆或复制数据、结构、,并将MySQL表的索引转换为新表?
这是我到目前为止发现的。
这将复制数据和结构,但不包括指数:
create table {new_table} select * from {old_table};
这将复制结构和索引,但不包括数据:
create table {new_table} like {old_table};
当前回答
要复制表及其结构,而不从其他数据库复制数据,请使用此选项。关于新的数据库sql类型
创建表格currentdatabase.tablename与旧数据库.tablename相似
其他回答
对于MySQL
CREATE TABLE newtable LIKE oldtable ;
INSERT newtable SELECT * FROM oldtable ;
对于MSSQL使用MyDatabase:
Select * into newCustomersTable from oldCustomersTable;
此SQL用于复制表,此处旧CustomersTable的内容将复制到新CustomersTable。确保数据库中不存在newCustomersTable。
// To copy specific column data use this one:
CREATE TABLE ut_axis_existrec LIKE ut_karvy_annexure; // To create new table
INSERT INTO ut_axis_existrec
(funding_ac,micr_no, warrant_no,
amount,invname,mfundcode,funding_dt,status,remarks1,amc_remark,created_at)
SELECT
t1.funding_ac,
t1.micr_no,
t1.warrant_no,
t1.amount,
t1.invname,
t1.mfund_code,
t1.funding_dt,
t1.status,
t1.remarks1,
t1.created_at
from ut_axis_karvy
inner join
ut_axis_karvy_master as t2
on t1.micr_no = t2.micr_no;
除了上面的解决方案之外,您可以使用AS将其集成到一条线上。
CREATE TABLE tbl_new AS SELECT * FROM tbl_old;
要复制表及其结构,而不从其他数据库复制数据,请使用此选项。关于新的数据库sql类型
创建表格currentdatabase.tablename与旧数据库.tablename相似
MySQL方式:
CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;