標籤:

SQL Practice - Sep. 2,18

SQL Practice - Sep. 2,18

題目:將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);


我的答案:

alter table titles_test rename to titles_2017;


MySQL的寫法和SQLite接近,不過還有另外一個版本:

rename tablename to newtablename

rename titles_test to titles_2017;

SQL Server和SQLite在這題上的寫法還是不太一樣的:

sp_rename tablename, newtablename

sp_rename titles_test, titles_2017;

推薦閱讀:

裝神必備:資料庫設計的範式
Python固化周期性的sql請求
mysql--實現oracle的row_number() over功能
文檔模型(JSON)使用介紹
學習SQL【10】-SQL高級處理

TAG:SQL | SQL語句 |