forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Reviewed-by: Jiang, Beibei <beibei.jiang@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
368 lines
31 KiB
HTML
368 lines
31 KiB
HTML
<a name="EN-US_TOPIC_0000001234200611"></a><a name="EN-US_TOPIC_0000001234200611"></a>
|
|
|
|
<h1 class="topictitle1">Table Operations</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164603_p153001227758">This section contains the migration syntax for migrating MySQL table operation. The migration syntax decides how the supported keywords/features are migrated.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_p1295019918158">For details, see the following topics:</p>
|
|
<ul id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_ul399519305156"><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li119969302158"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section135275238112">LIKE (Table Cloning)</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li91591237191512"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1277716559165">ADD|DROP COLUMN</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li15761154520154"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1625145611618">MODIFY (Column Modification)</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li198761553161518"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section185127566162">CHANGE (Column Modification)</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li7918192111611"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section777435610162">SET|DROP COLUMN DEFAULT VALUE</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li18892191116164"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section179989561167">DROP (Table Deletion)</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li9802122119160"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section142431157181611">TRUNCATE (Table Deletion)</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li167021330151610"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section11440115719160">LOCK</a></li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_li13943193321614"><a href="#EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section367216577163">RENAME (Table Renaming)</a></li></ul>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section135275238112"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section135275238112"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section135275238112"></a><h4 class="sectiontitle">LIKE (Table Cloning)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164665_p17157194614820">MySQL databases support <strong id="EN-US_TOPIC_0000001234200611__b144238412283">CREATE TABLE</strong>. <strong id="EN-US_TOPIC_0000001234200611__b148642039122810">LIKE</strong> is a method with which a table is created by cloning the old table structure, and this method is supported by <span id="EN-US_TOPIC_0000001234200611__text10892754124514">GaussDB(DWS)</span>. DSC will add additional table attribute information during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164665_p66158450506"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b3194825388">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164665_screen194633114518">CREATE TABLE IF NOT EXISTS `public`.`runoob_tbl_old`(
|
|
`dataType_1` YEAR,
|
|
`dataType_2` YEAR(4),
|
|
`dataType_3` YEAR DEFAULT '2018',
|
|
`dataType_4` TIME DEFAULT NULL
|
|
);
|
|
|
|
CREATE TABLE `runoob_tbl` (like `runoob_tbl_old`);</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164665_p8060118"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b161947211384">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164665_screen0945151925117">CREATE TABLE "public"."runoob_tbl_old"
|
|
(
|
|
"datatype_1" VARCHAR(4),
|
|
"datatype_2" VARCHAR(4),
|
|
"datatype_3" VARCHAR(4) DEFAULT '2018',
|
|
"datatype_4" TIME WITHOUT TIME ZONE DEFAULT NULL
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype_1");
|
|
|
|
CREATE TABLE "public"."runoob_tbl"( LIKE "public"."runoob_tbl_old"
|
|
INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING STORAGE);</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1277716559165"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1277716559165"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section1277716559165"></a><h4 class="sectiontitle">ADD|DROP COLUMN</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_p7574545962">MySQL and <span id="EN-US_TOPIC_0000001234200611__text312234144915">GaussDB(DWS)</span> use different statements for adding and deleting columns. DSC will perform adaptation based on GaussDB features during migration.</p>
|
|
<div class="caution" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_note9749104517138"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_p10148349141814">GaussDB does not support the update of sequence numbers in table definitions. Temporarily, DSC does not support the complete migration of the FIRST and AFTER features. So as a workaround, it simply deletes the keywords.</p>
|
|
</div></div>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_p8822521203711"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1440111573819">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_screen832116160817">CREATE TABLE IF NOT EXISTS `runoob_alter_test`(
|
|
`dataType1` int NOT NULL AUTO_INCREMENT,
|
|
`dataType2` FLOAT(10,2),
|
|
`dataType3` DOUBLE(20,8),
|
|
`dataType4` TEXT NOT NULL,
|
|
`dataType5` YEAR NOT NULL DEFAULT '2018',
|
|
`dataType6` DATETIME NOT NULL DEFAULT '2018-10-12 15:27:33.999999',
|
|
`dataType7` CHAR NOT NULL DEFAULT '',
|
|
`dataType8` VARCHAR(50),
|
|
`dataType9` VARCHAR(50) NOT NULL DEFAULT '',
|
|
`dataType10` TIME NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY(`dataType1`)
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
## A.
|
|
ALTER TABLE runoob_alter_test ADD dataType1_1 INT NOT NULL AFTER dataType1;
|
|
ALTER TABLE runoob_alter_test DROP dataType1_1;
|
|
|
|
## B.
|
|
ALTER TABLE runoob_alter_test ADD dataType1_1 INT NOT NULL FIRST;
|
|
ALTER TABLE runoob_alter_test DROP dataType1_1;
|
|
|
|
## C.
|
|
ALTER TABLE runoob_alter_test ADD COLUMN dataType1_1 INT NOT NULL AFTER dataType2;
|
|
ALTER TABLE runoob_alter_test DROP COLUMN dataType1_1;
|
|
|
|
## D.
|
|
ALTER TABLE runoob_alter_test ADD COLUMN dataType1_1 INT NOT NULL FIRST;
|
|
ALTER TABLE runoob_alter_test DROP COLUMN dataType1_1;
|
|
|
|
## E.
|
|
ALTER TABLE runoob_alter_test ADD COLUMN(dataType1_1 INT NOT NULL, dataType1_2 VARCHAR(200) NOT NULL);
|
|
ALTER TABLE runoob_alter_test DROP COLUMN dataType1_1, DROP COLUMN dataType1_2;
|
|
</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_p1431826173714"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b94409151381">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164714_screen14391919489">CREATE TABLE "public"."runoob_alter_test"
|
|
(
|
|
"datatype1" SERIAL NOT NULL,
|
|
"datatype2" FLOAT(10),
|
|
"datatype3" FLOAT(20),
|
|
"datatype4" TEXT NOT NULL,
|
|
"datatype5" VARCHAR(4) NOT NULL DEFAULT '2018',
|
|
"datatype6" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '2018-10-12 15:27:33.999999',
|
|
"datatype7" CHAR NOT NULL DEFAULT '',
|
|
"datatype8" VARCHAR(50),
|
|
"datatype9" VARCHAR(50) NOT NULL DEFAULT '',
|
|
"datatype10" TIME WITHOUT TIME ZONE NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY ("datatype1")
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype1");
|
|
|
|
-- A.
|
|
ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype1_1" INTEGER NOT NULL;
|
|
ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype1_1" RESTRICT;
|
|
|
|
-- B.
|
|
ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype1_1" INTEGER NOT NULL;
|
|
ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype1_1" RESTRICT;
|
|
|
|
-- C.
|
|
ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype1_1" INTEGER NOT NULL;
|
|
ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype1_1" RESTRICT;
|
|
|
|
-- D.
|
|
ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype1_1" INTEGER NOT NULL;
|
|
ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype1_1" RESTRICT;
|
|
|
|
-- E.
|
|
ALTER TABLE "public"."runoob_alter_test" ADD COLUMN "datatype1_1" VARCHAR(200) NOT NULL, ADD COLUMN "datatype1_2" VARCHAR(200) NOT NULL;
|
|
ALTER TABLE "public"."runoob_alter_test" DROP COLUMN "datatype1_1" RESTRICT, DROP COLUMN "datatype1_2" RESTRICT;</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1625145611618"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section1625145611618"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section1625145611618"></a><h4 class="sectiontitle">MODIFY (Column Modification)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164523_p7574545962">MySQL uses the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b226382618388">MODIFY</strong> keyword to change column data types and set <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1926312693811">NOT NULL</strong> constraints. DSC will perform adaptation based on GaussDB features during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164523_p8822521203711"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b18263726153818">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164523_screen146478312316">CREATE TABLE IF NOT EXISTS `runoob_alter_test`(
|
|
`dataType0` varchar(100),
|
|
`dataType1` bigint,
|
|
`dataType2` bigint,
|
|
`dataType3` bigint
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
## A.
|
|
ALTER TABLE runoob_alter_test MODIFY dataType1 smallint;
|
|
|
|
## B.
|
|
ALTER TABLE runoob_alter_test MODIFY dataType1 smallint NOT NULL;
|
|
|
|
## C.
|
|
ALTER TABLE runoob_alter_test MODIFY dataType1 smallint NOT NULL FIRST;
|
|
|
|
## D.
|
|
ALTER TABLE runoob_alter_test MODIFY dataType1 smallint NOT NULL AFTER dataType3;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164523_p1431826173714"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b126372663815">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164523_screen173941613113">CREATE TABLE "public"."runoob_alter_test"
|
|
(
|
|
"datatype0" VARCHAR(100),
|
|
"datatype1" BIGINT,
|
|
"datatype2" BIGINT,
|
|
"datatype3" BIGINT
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype0");
|
|
|
|
-- A.
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype1" SET DATA TYPE SMALLINT;
|
|
|
|
-- B.
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype1" SET DATA TYPE SMALLINT, ALTER COLUMN "datatype1" SET NOT NULL;
|
|
|
|
-- C.
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype1" SET DATA TYPE SMALLINT, ALTER COLUMN "datatype1" SET NOT NULL;
|
|
|
|
-- D.
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype1" SET DATA TYPE SMALLINT, ALTER COLUMN "datatype1" SET NOT NULL;</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section185127566162"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section185127566162"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section185127566162"></a><h4 class="sectiontitle">CHANGE (Column Modification)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164478_p2091463310273">MySQL uses the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1339923683814">CHANGE</strong> keyword to change column names and data types and set <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b18399636143812">NOT NULL</strong> constraints. DSC will perform adaptation based on GaussDB features during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164478_p8060118"><strong id="EN-US_TOPIC_0000001234200611__b130274694">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164478_screen897275693011">CREATE TABLE IF NOT EXISTS `runoob_alter_test`(
|
|
`dataType0` varchar(128),
|
|
`dataType1` bigint,
|
|
`dataType2` bigint,
|
|
`dataType3` bigint,
|
|
`dataType4` bigint
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
## A.
|
|
ALTER TABLE runoob_alter_test CHANGE dataType1 dataType1New VARCHAR(50);
|
|
|
|
## B.
|
|
ALTER TABLE runoob_alter_test CHANGE dataType2 dataType2New VARCHAR(50) NOT NULL;
|
|
|
|
## C.
|
|
ALTER TABLE runoob_alter_test CHANGE dataType3 dataType3New VARCHAR(100) FIRST;
|
|
|
|
## D.
|
|
ALTER TABLE runoob_alter_test CHANGE dataType4 dataType4New VARCHAR(50) AFTER dataType1;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164478_p1431826173714"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b12399136183818">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164478_screen1573016073113">CREATE TABLE "public"."runoob_alter_test"
|
|
(
|
|
"datatype0" VARCHAR(128),
|
|
"datatype1" BIGINT,
|
|
"datatype2" BIGINT,
|
|
"datatype3" BIGINT,
|
|
"datatype4" BIGINT
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype0");
|
|
|
|
-- A.
|
|
ALTER TABLE "public"."runoob_alter_test" RENAME COLUMN "datatype1" TO "datatype1new";
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype1new" SET DATA TYPE VARCHAR(50);
|
|
|
|
-- B.
|
|
ALTER TABLE "public"."runoob_alter_test" RENAME COLUMN "datatype2" TO "datatype2new";
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype2new" SET DATA TYPE VARCHAR(50), ALTER COLUMN "datatype2new" SET NOT NULL;
|
|
|
|
-- C.
|
|
ALTER TABLE "public"."runoob_alter_test" RENAME COLUMN "datatype3" TO "datatype3new";
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype3new" SET DATA TYPE VARCHAR(100);
|
|
|
|
-- D.
|
|
ALTER TABLE "public"."runoob_alter_test" RENAME COLUMN "datatype4" TO "datatype4new";
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype4new" SET DATA TYPE VARCHAR(50);</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section777435610162"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section777435610162"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section777435610162"></a><h4 class="sectiontitle">SET|DROP COLUMN DEFAULT VALUE</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164473_p19751438112911">In MySQL, the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1608046153813">COLUMN</strong> keyword can be omitted when the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b8608114683815">ALTER</strong> statement is used to set the default value of a column. DSC will perform adaptation based on GaussDB features during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164473_p8060118"><strong id="EN-US_TOPIC_0000001234200611__b157247896">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164473_screen173026529304">CREATE TABLE IF NOT EXISTS `runoob_alter_test`(
|
|
`dataType1` int NOT NULL AUTO_INCREMENT,
|
|
`dataType2` FLOAT(10,2),
|
|
`dataType3` DOUBLE(20,8),
|
|
`dataType4` TEXT NOT NULL,
|
|
`dataType5` YEAR NOT NULL DEFAULT '2018',
|
|
`dataType6` DATETIME NOT NULL DEFAULT '2018-10-12 15:27:33.999999',
|
|
`dataType7` CHAR NOT NULL DEFAULT '',
|
|
`dataType8` VARCHAR(50),
|
|
`dataType9` VARCHAR(50) NOT NULL DEFAULT '',
|
|
`dataType10` TIME NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY(`dataType1`)
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
ALTER TABLE runoob_alter_test ALTER dataType2 SET DEFAULT 1;
|
|
ALTER TABLE runoob_alter_test ALTER COLUMN dataType2 SET DEFAULT 3;
|
|
ALTER TABLE runoob_alter_test ALTER dataType2 DROP DEFAULT;
|
|
ALTER TABLE runoob_alter_test ALTER COLUMN dataType2 DROP DEFAULT;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164473_p1431826173714"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1960844623815">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164473_screen18665125423015">CREATE TABLE "public"."runoob_alter_test"
|
|
(
|
|
"datatype1" SERIAL NOT NULL,
|
|
"datatype2" FLOAT(10),
|
|
"datatype3" FLOAT(20),
|
|
"datatype4" TEXT NOT NULL,
|
|
"datatype5" VARCHAR(4) NOT NULL DEFAULT '2018',
|
|
"datatype6" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '2018-10-12 15:27:33.999999',
|
|
"datatype7" CHAR NOT NULL DEFAULT '',
|
|
"datatype8" VARCHAR(50),
|
|
"datatype9" VARCHAR(50) NOT NULL DEFAULT '',
|
|
"datatype10" TIME WITHOUT TIME ZONE NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY ("datatype1")
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype1");
|
|
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype2" SET DEFAULT 1;
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype2" SET DEFAULT 3;
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype2" DROP DEFAULT;
|
|
ALTER TABLE "public"."runoob_alter_test" ALTER COLUMN "datatype2" DROP DEFAULT;</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section179989561167"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section179989561167"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section179989561167"></a><h4 class="sectiontitle">DROP (Table Deletion)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164709_p186313195351">Both <span id="EN-US_TOPIC_0000001234200611__text1321887154918">GaussDB(DWS)</span> and MySQL can use the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b757515617389">DROP</strong> statement to delete tables, but <span id="EN-US_TOPIC_0000001234200611__text1958020141713">GaussDB(DWS)</span> does not support the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b4575256183815">RESTRICT | CASCADE</strong> keyword in <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b25754569385">DROP</strong>. DSC will delete the keywords during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164709_p8822521203711"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b19575175616388">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164709_screen9190133515375">CREATE TABLE IF NOT EXISTS `public`.`express_elb_server`(
|
|
`runoob_id` VARCHAR(10),
|
|
`runoob_title` VARCHAR(100) NOT NULL,
|
|
`runoob_author` VARCHAR(40) NOT NULL,
|
|
`submission_date` VARCHAR(10)
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
DROP TABLE `public`.`express_elb_server` RESTRICT;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164709_p1431826173714"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b45751956143815">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164709_screen410063910371">CREATE TABLE "public"."express_elb_server"
|
|
(
|
|
"runoob_id" VARCHAR(10),
|
|
"runoob_title" VARCHAR(100) NOT NULL,
|
|
"runoob_author" VARCHAR(40) NOT NULL,
|
|
"submission_date" VARCHAR(10)
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("runoob_id");
|
|
DROP TABLE "public"."express_elb_server";</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section142431157181611"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section142431157181611"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section142431157181611"></a><h4 class="sectiontitle">TRUNCATE (Table Deletion)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164430_p8060118">In MySQL, the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b38541749390">TABLE</strong> keyword can be omitted when the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b18547418397">TRUNCATE</strong> statement is used to delete table data. GaussDB does not support this usage. In addition, DSC will add <strong id="EN-US_TOPIC_0000001234200611__b11628201611">CONTINUE IDENTITY RESTRICT</strong> during <strong id="EN-US_TOPIC_0000001234200611__b146281104110">TRUNCATE</strong> migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164430_p715302393"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b108559453916">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164430_screen54461414398">TRUNCATE TABLE `public`.`test_create_table01`;
|
|
TRUNCATE TEST_CREATE_TABLE01;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164430_p5378552390"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b10855154183911">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164430_screen5601161615398">TRUNCATE TABLE "public"."test_create_table01" CONTINUE IDENTITY RESTRICT;
|
|
TRUNCATE TABLE "public"."test_create_table01" CONTINUE IDENTITY RESTRICT;</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section11440115719160"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section11440115719160"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section11440115719160"></a><h4 class="sectiontitle">LOCK</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_p102116541238"><span id="EN-US_TOPIC_0000001234200611__text8512111294919">GaussDB(DWS)</span> does not support the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b488601593920">ALTER TABLE </strong><em id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_i178877155391">tbName </em><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b9887161511396">LOCK</strong> statement of MySQL, which will be deleted by DSC during migration.</p>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_p896271452516"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b588714159394">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_screen267624012514">CREATE TABLE IF NOT EXISTS `runoob_alter_test`(
|
|
`dataType1` int NOT NULL AUTO_INCREMENT,
|
|
`dataType2` FLOAT(10),
|
|
`dataType4` TEXT NOT NULL,
|
|
`dataType5` YEAR NOT NULL DEFAULT '2018',
|
|
`dataType6` DATETIME NOT NULL,
|
|
`dataType7` CHAR NOT NULL DEFAULT '',
|
|
`dataType8` VARCHAR(50),
|
|
`dataType9` VARCHAR(50) NOT NULL DEFAULT '',
|
|
`dataType10` TIME NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY(`dataType1`)
|
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
## A.
|
|
ALTER TABLE runoob_alter_test LOCK DEFAULT;
|
|
|
|
## B.
|
|
ALTER TABLE runoob_alter_test LOCK=DEFAULT;
|
|
|
|
## C.
|
|
ALTER TABLE runoob_alter_test LOCK EXCLUSIVE;
|
|
|
|
## D.
|
|
ALTER TABLE runoob_alter_test LOCK=EXCLUSIVE;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_p10469192052519"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b15887151513394">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_screen12559134312512">CREATE TABLE "public"."runoob_alter_test"
|
|
(
|
|
"datatype1" SERIAL NOT NULL,
|
|
"datatype2" FLOAT(10),
|
|
"datatype4" TEXT NOT NULL,
|
|
"datatype5" VARCHAR(4) NOT NULL DEFAULT '2018',
|
|
"datatype6" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
|
"datatype7" CHAR NOT NULL DEFAULT '',
|
|
"datatype8" VARCHAR(50),
|
|
"datatype9" VARCHAR(50) NOT NULL DEFAULT '',
|
|
"datatype10" TIME WITHOUT TIME ZONE NOT NULL DEFAULT '10:20:59',
|
|
PRIMARY KEY ("datatype1")
|
|
)
|
|
WITH ( ORIENTATION = ROW, COMPRESSION = NO )
|
|
NOCOMPRESS
|
|
DISTRIBUTE BY HASH ("datatype1");
|
|
|
|
-- A.
|
|
|
|
-- B.
|
|
|
|
-- C.
|
|
|
|
-- D.</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164681_p8060118"></p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section367216577163"><a name="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_section367216577163"></a><a name="en-us_topic_0238518441_en-us_topic_0237362250_section367216577163"></a><h4 class="sectiontitle">RENAME (Table Renaming)</h4><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p11532411115112">The statement for renaming a table in MySQL is slightly different from that in <span id="EN-US_TOPIC_0000001234200611__text084213154498">GaussDB(DWS)</span>. DSC will perform adaptation based on GaussDB features during migration.</p>
|
|
<div class="caution" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_note4707640687"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p71171916121011">Currently, DSC does not support original table names prefixed with <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b108775205249">DATABASE/SCHEMA.</strong></p>
|
|
</div></div>
|
|
<ol id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_ol33447017537"><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_li163456014530">MySQL uses the <strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b19923105114392">RENAME TABLE</strong> statement to change a table name.<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p1227645615546"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1792445114393">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_screen10792151117551"># Rename a single table.
|
|
RENAME TABLE DEPARTMENT TO NEWDEPT;
|
|
|
|
# Rename multiple tables.
|
|
RENAME TABLE NEWDEPT TO NEWDEPT_02,PEOPLE TO PEOPLE_02;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p43776225514"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b1892485193920">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_screen11734201310552">-- Rename a single table.
|
|
ALTER TABLE "public"."department" RENAME TO "newdept";
|
|
|
|
-- Rename multiple tables.
|
|
ALTER TABLE "public"."newdept" RENAME TO "newdept_02";
|
|
ALTER TABLE "public"."people" RENAME TO "people_02";</pre>
|
|
</li><li id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_li141013269533">In MySQL, the <strong id="EN-US_TOPIC_0000001234200611__b19196648103019">ALTER TABLE RENAME</strong> statement is used to change a table name. When this statement is migrated by DSC, the keyword <strong id="EN-US_TOPIC_0000001234200611__b151158159313">AS</strong> is converted to <strong id="EN-US_TOPIC_0000001234200611__b54381224173117">TO</strong>.<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p6513192815515"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b59241251173918">Input</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_screen151315280557">## A.
|
|
ALTER TABLE runoob_alter_test RENAME TO runoob_alter_testnew;
|
|
|
|
## B.
|
|
ALTER TABLE runoob_alter_testnew RENAME AS runoob_alter_testnewnew;</pre>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p16513132825519"><strong id="EN-US_TOPIC_0000001234200611__en-us_topic_0237712427_b179241151143917">Output</strong></p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_screen1513228105515">-- A.
|
|
ALTER TABLE "public"."runoob_alter_test" RENAME TO "runoob_alter_testnew";
|
|
|
|
-- B.
|
|
ALTER TABLE "public"."runoob_alter_testnew" RENAME TO "runoob_alter_testnewnew";</pre>
|
|
</li></ol>
|
|
<p id="EN-US_TOPIC_0000001234200611__en-us_topic_0238518441_en-us_topic_0237362250_en-us_topic_0214164669_p8060118"></p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_sct_0013.html">MySQL Syntax Migration</a></div>
|
|
</div>
|
|
</div>
|
|
|