mysql引用和select-into

unhi4e5o  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(190)

我需要一些帮助一些tsql到mysql的翻译:)。

select id,
       title,
       release_date, 
       imdb_id, 
       spoken_languages, 
       runtime
  into [DatabaseDestination].dbo.tableDestination
  from [DatabaseSource].dbo.tableSource;

ALTER TABLE [DatabaseDestination].dbo.tableDestination;
ALTER COLUMN id float NOT NULL;
ALTER TABLE [DatabaseDestination].dbo.tableDestination add primary key (id);

如何在mysql[databasedestination].dbo.dmovie\u详细信息中进行这种通用引用或导航,以及如何翻译上面的代码?

inn6fuwd

inn6fuwd1#

使用 INSERT INTO ... SELECT :

INSERT INTO db2.tableDestination (id, title, release_date, imdb_id, spoken_languages,
    runtime)
SELECT id, title, release_date, imdb_id, spoken_languages, runtime
FROM db1.tableSource;

一般来说,最好总是指定要插入的列,尽管mysql不需要。我实际上不知道目标表中列的名称,所以我做了一个有根据的猜测,并假设它们与源表中的列名相同。
对于其他步骤,您应该在mysql中创建目标表时处理模式问题。

wbgh16ku

wbgh16ku2#

使用insert into---select from和for table navigation编写类似于databasedestination.tabledestination

insert into DatabaseDestination.tableDestination(id, title,release_date, imdb_id, spoken_languages, runtime)
      select id, title,release_date, imdb_id, spoken_languages, runtime from DatabaseSource.tableSource;

ALTER TABLE DatabaseDestination.tableDestination
ALTER COLUMN id float NOT NULL;
ALTER TABLE DatabaseDestination.tableDestination add primary key (id);

相关问题