首页 > 试题广场 >

将titles_test表名修改为titles_2017

[编程题]将titles_test表名修改为titles_2017
  • 热度指数:79043 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
将titles_test表名修改为titles_2017。
CREATE TABLE IF NOT EXISTS titles_test (
id int(11) not null primary key,
emp_no int(11) NOT NULL,
title varchar(50) NOT NULL,
from_date date NOT NULL,
to_date date DEFAULT NULL);

insert into titles_test values ('1', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('2', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('3', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('4', '10004', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('5', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('6', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('7', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01');
示例1

输入

drop table if exists titles_test;
drop table if exists titles_2017;
CREATE TABLE titles_test (
   id int(11) not null primary key,
   emp_no  int(11) NOT NULL,
   title  varchar(50) NOT NULL,
   from_date  date NOT NULL,
   to_date  date DEFAULT NULL);

insert into titles_test values
('1', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('2', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('3', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('4', '10004', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('5', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('6', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('7', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01');

输出

1|10001|Senior Engineer|1986-06-26|9999-01-01
2|10002|Staff|1996-08-03|9999-01-01
3|10003|Senior Engineer|1995-12-03|9999-01-01
4|10004|Senior Engineer|1995-12-03|9999-01-01
5|10001|Senior Engineer|1986-06-26|9999-01-01
6|10002|Staff|1996-08-03|9999-01-01
7|10003|Senior Engineer|1995-12-03|9999-01-01
RENAME TO 语句更改表名的基本运用,详情可参考:
ALTER TABLE titles_test RENAME TO titles_2017

编辑于 2017-07-22 16:54:37 回复(10)
更多回答
RENAME TABLE titles_test to titles_2017;

ALTER TABLE titles_test RENAME TO titles_2017;

#两个方法在mysql控制台中都可以成功,而在牛客中只有第二个可以ac

发表于 2017-09-01 01:43:25 回复(3)

题目是sqlite3,必须要加to

alter table titles_test rename to titles_2017

如果是mysql,不用加to

alter table titles_test rename titles_2017
发表于 2017-11-08 20:23:56 回复(2)

MySQL 和 SqlLite都支持的用法:
alter table tname_old rename to tname_new

另外,还有一种低效的方法:先创建表,再删除表:
create table tname_new as select *from tname_old;
drop table tname_old;

注,在MySQL中,可以这样使用rename:

reanme table tname_old to tname_new

通过代码如下:
方法一:

alter table titles_test rename to titles_2017

方法二:

create table titles_2017 as select *from titles_test;
drop table titles_test;
发表于 2018-09-07 11:04:59 回复(0)
alter table titles_test rename to titles_2017

修改表名:alter table 旧表名 rename to 新表名

编辑于 2017-08-31 00:06:41 回复(0)
alter table titles_test rename as titles_2017;
rename table  titles_test to titles_2017;
二选一都可以
发表于 2022-04-16 17:06:11 回复(0)
-- rename table t1 to t2; mysql修改t1表名为t2
-- alter table t1 rename to t2; sqlite3写法
alter table titles_test rename to titles_2017;
发表于 2020-07-20 11:04:13 回复(0)
ALTER TABLE 'titles_test' RENAME TO 'titles_2017';
发表于 2019-02-02 23:38:56 回复(0)
mysql中修改表信息的规则。
alter table 表名 change 原列名 新列名  类型; --修改表的列属性名
alter table 表名 modify 列名 类型 ;  --修改表的类类型
alter table 表名 drop 列名;  --删除表的某一列
alter table 表名 add  列名 类型;--添加某一列
alter table 表名 rename 新表名; --修改表名
发表于 2020-07-07 10:35:25 回复(3)
考点:更改表使用alter, 重命名使用 rename
alter table titles_test rename titles_2017


发表于 2021-03-27 15:04:50 回复(0)
ALTER TABLE titles_test RENAME TO titles_2017

ALTER TABLE 旧表名 RENAME TO 新表名
发表于 2024-04-26 10:24:41 回复(0)
RENAME TABLE titles_test TO titles_2017;
OR:
ALTER TABLE titles_test RENAME AS titles_2017;

发表于 2024-04-01 11:47:04 回复(0)
create table titles_2017 (
    select * from titles_test
);

编辑于 2024-02-05 13:47:03 回复(0)
ALTER TABLE titles_test RENAME TO titles_2017

发表于 2023-11-27 09:10:15 回复(0)
RENAME TABLE titles_test TO titles_2017;

发表于 2023-08-11 10:40:56 回复(0)
alter table titles_test rename as titles_2017

发表于 2023-06-15 11:15:59 回复(0)
与impala相同:
alter table titles_test rename to titles_2017

发表于 2023-04-28 17:54:14 回复(0)
rename table titles_test to titles_2017
发表于 2023-03-17 10:24:54 回复(0)
变更表名/列名,新增字段 变更表名 alter table xxx rename to xxx alter table titles_test rename to titles_2017;变更列名 alter table xxx rename colunm xx to x alter table ."BAS_PERSON_INFO" rename column SEX_NAME2 to SEX_NAME 。新增字段:变更表名 新增的字段是啥,数据类型是啥 alter table xxx add column xx vachar(1024) ALTER TABLE ".BGT_FISCAL_ADJ_BILL" ADD COLUMN BGT_DEC ;
发表于 2023-02-08 15:21:16 回复(0)
rename table titles_test to titles_2017

发表于 2022-12-08 16:23:15 回复(0)

问题信息

难度:
106条回答 13528浏览

热门推荐

通过挑战的用户

查看代码