列表

详情


SQL239. 将titles_test表名修改为titles_2017

描述

将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');
后台会执行下面SQL语句来对比输出:
select * from titles_2017 order by id;

示例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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3196KB, 提交时间: 2020-07-07

alter table titles_test rename to titles_2017;

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3232KB, 提交时间: 2021-07-22

ALTER TABLE titles_test
RENAME TO titles_2017;

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2021-06-23

create table titles_2017 as select *from titles_test;
drop table titles_test;

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2020-11-23

alter table titles_test rename to titles_2017

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2020-11-23

alter table titles_test rename to titles_2017

上一题