日期:2014-05-16  浏览次数:20885 次

无法创建视图
大家帮我看看下面的语句为什么无法创建视图。谢谢!!!
SQL code

create view 'v' as 
select 
t.id as tid,
t.title,
t.hits,
t.reply_count,
t.last_reply_id,
t.last_reply_time,
t.last_reply_nick_name,
t.create_time,
u.id as uid,
u.nick_name,
ts.icon_url
from topic as t 
inner join user as u on t.user_id=u.id 
inner join topic_state_type as ts on t.state=ts.id


这是错误信息:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''v' as select t.id as tid, t.title, t.hits, t.reply_count, t.last_reply_' at line 1


而下面这样是能正确运行的
SQL code

select 
t.id as tid,
t.title,
t.hits,
t.reply_count,
t.last_reply_id,
t.last_reply_time,
t.last_reply_nick_name,
t.create_time,
u.id as uid,
u.nick_name,
ts.icon_url
from topic as t 
inner join user as u on t.user_id=u.id 
inner join topic_state_type as ts on t.state=ts.id



运行环境:
MySQL
服务器: localhost via TCP/IP
服务器版本: 5.1.62-community
协议版本: 10
用户: root@localhost
MySQL 字符集: UTF-8 Unicode (utf8) 
网站服务器
Apache/2.2.22 (Win32) PHP/5.2.17
MySQL 客户端版本: 5.0.90
PHP 扩展: mysql
phpMyAdmin
版本信息: 3.3.7

谢谢!!!

------解决方案--------------------
把引号去掉。 为什么要加引号?!

create view v as 
select 
t.id as tid,
t.title,
t.hits,
t.reply_count,
t.last_reply_id,
t.last_reply_time,
t.last_reply_nick_name,
t.create_time,
u.id as uid,
u.nick_name,
ts.icon_url
from topic as t 
inner join user as u on t.user_id=u.id 
inner join topic_state_type as ts on t.state=ts.id