In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you what is the difference between create as and create like in Mysql, I hope you read this article after a big harvest, let's discuss it together!
You may find it very convenient to use Navicat Premium, such as copying tables or data structures. In fact, this method of copying table data or structures is realized by creating table as and creating table like.
Careful friends will ask, what is the difference between them?... No more nonsense, straight to the point:
For example, here's a table of data t1:
DROP TABLE IF EXISTS `t1`; CREATE TABLE `t1`( `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID, self-increment',`uid` bigint(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT ' user uid', `nickname` varchar(25) CHARACTER SET utf8 COLATE utf8_general_ci DEFAULT NULL COMMENT '',`name` varchar(20) CHARACTER SET utf8 COLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'USER NAME', PRIMARY KEY (`id`) USING BTREE, INDEX `unn`(`uid`, `name`, `nickname`) USING BTREE) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ------------------------------ Records of t1-- ----------------------------INSERT INTO `t1` VALUES (3, 100, 'kaven', 'test3');INSERT INTO `t1` VALUES (2, 101, 'maha', 'test2');INSERT INTO `t1` VALUES (4, 102, 'loose', 'test4');INSERT INTO `t1` VALUES (5, 105, 'balala', 'test5');
Note the index above:
Create As Copy Table
create table t1_copy as select * from t1 where 1=2#or create table t1_copy as select * from t1 limit 0
Here we only need the table structure, so the above where 1=2 or lmit 0 query is empty data. We will find that the new table t1_copy has no index:
Index information for t1 table (source table) is missing and only the table structure is the same. (If you want to copy data, remove limit 0, that is, copy all the data queried)
Create like Copy table
create table t1_copy2 like t1
We find that the new table created by like contains the full table structure and index information of the source table.
Summary:
As is used to create the same table structure and copy the source table data.
Like is used to create complete table structures and full indexes.
Note: Both methods do not copy permissions on tables when copying tables. For example, after copying table AA, table AA does not have permissions similar to those of table A. Interested friends can try
After reading this article, I believe you have a certain understanding of the differences between create as and create like in Mysql. If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.