不知道“select 1 from sys.systable where table_name”是什么意思

nongfuxu 2016-03-09 08:12:42
设计好物理数据模型、导出sql语句后,在导出的文件中看到以下语句,
if exists(select 1 from sys.systable where table_name='tb_Area' and table_type='BASE') then
drop table dbo.tb_Area
end if;


这里,tb_Area是我给数据表起的名称。请教select 1 from sys.systable是什么意思?

另外在执行这个SQL文件时也报错。我应该怎样查找问题?
...全文
4271 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yccf 2017-06-20
  • 打赏
  • 举报
回复
楼上完全正解
Amina_L 2017-06-17
  • 打赏
  • 举报
回复
这个查询的意思是判断你的数据库中是否有这个表,如果有就删除; 说有语法错误的原因可能是你的connection configure有问题,可以贴出来看看
猎奇567 2016-03-10
  • 打赏
  • 举报
回复
产生的是Sybase SQL anywhere数据库的SQL,连接SQL Server数据库执行?
jlwei888 2016-03-10
  • 打赏
  • 举报
回复
系统表,就看表tb_area 是否存在,是就删除,再创建
nongfuxu 2016-03-09
  • 打赏
  • 举报
回复
已知 select 1 from == select * from 那么这里的sys.systable是指哪个? 在文件夹中搜索“sys.systable”,没有找到它。
nongfuxu 2016-03-09
  • 打赏
  • 举报
回复
在PD16中,运行sql文件报错如下图所示。
nongfuxu 2016-03-09
  • 打赏
  • 举报
回复
由PD16生成的sql文件代码如下
/*==============================================================*/
/* DBMS name:      New DBMS                                     */
/* Created on:     2016/3/9 20:03:14                            */
/*==============================================================*/


if exists(select 1 from sys.systable where table_name='tb_Area' and table_type='BASE') then
   drop table dbo.tb_Area
end if;

if exists(select 1 from sys.systable where table_name='tb_City' and table_type='BASE') then
   drop table dbo.tb_City
end if;

if exists(select 1 from sys.systable where table_name='tb_Controller' and table_type='BASE') then
   drop table dbo.tb_Controller
end if;

if exists(select 1 from sys.systable where table_name='tb_Intersection' and table_type='BASE') then
   drop table dbo.tb_Intersection
end if;

if exists(select 1 from sys.systable where table_name='tb_IntersectionPeriodPhase' and table_type='BASE') then
   drop table dbo.tb_IntersectionPeriodPhase
end if;

if exists(select 1 from sys.systable where table_name='tb_PhaseConflict' and table_type='BASE') then
   drop table dbo.tb_PhaseConflict
end if;

if exists(select 1 from sys.systable where table_name='tb_PhasesDetail' and table_type='BASE') then
   drop table dbo.tb_PhasesDetail
end if;

if exists(select 1 from sys.systable where table_name='tb_SubArea' and table_type='BASE') then
   drop table dbo.tb_SubArea
end if;

/*==============================================================*/
/* User: dbo                                                    */
/*==============================================================*/
/*==============================================================*/
/* Table: tb_Area                                               */
/*==============================================================*/
create table dbo.tb_Area (
AreaID int not null,
AreaName varchar,
CityID int not null
);

/*==============================================================*/
/* Table: tb_City                                               */
/*==============================================================*/
create table dbo.tb_City (
CityID int not null default '(1000)',
CityName varchar  default '未定义'
);

/*==============================================================*/
/* Table: tb_Controller                                         */
/*==============================================================*/
create table dbo.tb_Controller (
ControllerID int not null,
ControllerName varchar not null default '新源22路控制器',
ControllerType varchar not null default '22路控制器'
);

/*==============================================================*/
/* Table: tb_Intersection                                       */
/*==============================================================*/
create table dbo.tb_Intersection (
IntersectionID int not null default '(0)',
IntersectionName varchar not null default '未定',
StreetNameEW varchar not null default '未定',
StreetNameSN varchar not null default '未定',
SubAreaID int not null default '(0)',
LampEWType varchar not null,
LampSNType varchar not null,
LaneNumberEW int not null,
LaneNumberSN int not null,
ControllerID int not null default '(0)',
Position1X int not null default '(0)',
Position1Y int not null default '(0)',
Position2X int not null default '(0)',
Position2Y int not null default '(0)',
Position3X int not null default '(0)',
Position3Y int not null default '(0)',
Position4X int not null default '(0)',
Position4Y int not null default '(0)'
);

/*==============================================================*/
/* Table: tb_IntersectionPeriodPhase                            */
/*==============================================================*/
create table dbo.tb_IntersectionPeriodPhase (
TotalPeriodPhaseID int not null default '(10)',
IntersectionID int not null default '(0)',
InterPeriodPhaseNo int not null default '(1)',
PhasesNumber int not null default '(4)'
);

/*==============================================================*/
/* Table: tb_PhaseConflict                                      */
/*==============================================================*/
create table dbo.tb_PhaseConflict (
ID int not null,
IntersectionID int not null default '(0)',
"Rows" int not null default '(0)',
LampName varchar,
EL varchar not null default 'R',
ET varchar not null default 'R',
ER varchar not null default 'R',
SL varchar not null default 'R',
ST varchar not null default 'R',
SR varchar not null default 'R',
WL varchar not null default 'R',
WT varchar not null default 'R',
WR varchar not null default 'R',
NL varchar not null default 'R',
NT varchar not null default 'R',
NR varchar not null default 'R',
EW varchar not null default 'R',
SW varchar not null default 'R',
WW varchar not null default 'R',
NW varchar not null default 'R'
);

/*==============================================================*/
/* Table: tb_PhasesDetail                                       */
/*==============================================================*/
create table dbo.tb_PhasesDetail (
TotalPhaseID int not null,
TotalPeriodPhaseID int not null,
PhaseNo int not null default '(0)',
PhaseTime_Isolate int not null default '(20)',
PhaseTime_FlexiLink int not null default '(20)',
LampEL varchar not null default 'C',
LampET varchar not null default 'C',
LampER varchar not null default 'C',
LampEP1 varchar not null default 'C',
LampEP2 varchar not null default 'C',
LampSL varchar not null default 'C',
LampST varchar not null default 'C',
LampSR varchar not null default 'C',
LampSP1 varchar not null default 'C',
LampSP2 varchar not null default 'C',
LampWL varchar not null default 'C',
LampWT varchar not null default 'C',
LampWR varchar not null default 'C',
LampWP1 varchar not null default 'C',
LampWP2 varchar not null default 'C',
LampNL varchar not null default 'C',
LampNT varchar not null default 'C',
LampNR varchar not null default 'C',
LampNP1 varchar not null default 'C',
LampNP2 varchar not null default 'C'
);

/*==============================================================*/
/* Table: tb_SubArea                                            */
/*==============================================================*/
create table dbo.tb_SubArea (
SubAreaID int not null,
SubAreaName varchar  default '待定',
AreaID int not null default '(0)'
);

if exists(select 1 from sys.sysforeignkey where role='FK_CHOOSE_C_CHOOSE_CO_COURSES') then alter table choose_course delete foreign key FK_CHOOSE_C_CHOOSE_CO_COURSES end if; if exists(select 1 from sys.sysforeignkey where role='FK_CHOOSE_C_CHOOSE_CO_STUDENT') then alter table choose_course delete foreign key FK_CHOOSE_C_CHOOSE_CO_STUDENT end if; if exists(select 1 from sys.sysforeignkey where role='FK_STUDENT_HAVE_STUD_SCHOOL') then alter table student delete foreign key FK_STUDENT_HAVE_STUD_SCHOOL end if; if exists(select 1 from sys.sysforeignkey where role='FK_TEACH_TE_TEACH_TEA_COURSES') then alter table teach_teachers delete foreign key FK_TEACH_TE_TEACH_TEA_COURSES end if; if exists(select 1 from sys.sysforeignkey where role='FK_TEACH_TE_TEACH_TEA_TEACHER') then alter table teach_teachers delete foreign key FK_TEACH_TE_TEACH_TEA_TEACHER end if; if exists(select 1 from sys.sysforeignkey where role='FK_TEACHER_HAVE_TEAC_SCHOOL') then alter table teacher delete foreign key FK_TEACHER_HAVE_TEAC_SCHOOL end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='choose_course2_FK' and t.table_name='choose_course' ) then drop index choose_course.choose_course2_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='choose_course_FK' and t.table_name='choose_course' ) then drop index choose_course.choose_course_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='choose_course_PK' and t.table_name='choose_course' ) then drop index choose_course.choose_course_PK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='courses_PK' and t.table_name='courses' ) then drop index courses.courses_PK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='school_PK' and t.table_name='school' ) then drop index school.school_PK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='have_student_FK' and t.table_name='student' ) then drop index student.have_student_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='student_PK' and t.table_name='student' ) then drop index student.student_PK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='teach_teachers2_FK' and t.table_name='teach_teachers' ) then drop index teach_teachers.teach_teachers2_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='teach_teachers_FK' and t.table_name='teach_teachers' ) then drop index teach_teachers.teach_teachers_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='teach_teachers_PK' and t.table_name='teach_teachers' ) then drop index teach_teachers.teach_teachers_PK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='have_teacher_FK' and t.table_name='teacher' ) then drop index teacher.have_teacher_FK end if; if exists( select 1 from sys.sysindex i, sys.systable t where i.table_id=t.table_id and i.index_name='teacher_PK' and t.table_name='teacher' ) then drop index teacher.teacher_PK end if; if exists( select 1 from sys.systable where table_name='choose_course' and table_type='BASE' ) then drop table choose_course end if; if exists( select 1 from sys.systable where table_name='courses' and table_type='BASE' ) then drop table courses end if; if exists( select 1 from sys.systable where table_name='school' and table_type='BASE' ) then drop table school end if; if exists( select 1 from sys.systable where table_name='student' and table_type='BASE' ) then drop table student end if; if exists( select 1 from sys.systable where table_name='teach_teachers' and table_type='BASE' ) then drop table teach_teachers end if; if exists( select 1 from sys.systable where table_name='teacher' and table_type='BASE' ) then drop table teacher end if; /*==============================================================*/ /* Table: choose_course */ /*==============================================================*/ create table choose_course ( course_id varchar(16) not null, student_id varchar(16) not null, score decimal(5,2), primary key (course_id, student_id) ); /*==============================================================*/ /* Index: choose_course_PK */ /*==============================================================*/ create unique index choose_course_PK on choose_course ( course_id ASC, student_id ASC ); /*==============================================================*/ /* Index: choose_course_FK */ /*==============================================================*/ create index choose_course_FK on choose_course ( course_id ASC ); /*==============================================================*/ /* Index: choose_course2_FK */ /*==============================================================*/ create index choose_course2_FK on choose_course ( student_id ASC ); /*==============================================================*/ /* Table: courses */ /*==============================================================*/ create table courses ( course_id varchar(16) not null, course_name varchar(32), course_content varchar(255), course_book varchar(64), primary key (course_id) ); /*==============================================================*/ /* Index: courses_PK */ /*==============================================================*/ create unique index courses_PK on courses ( course_id ASC ); /*==============================================================*/ /* Table: school */ /*==============================================================*/ create table school ( school_id varchar(16) not null, school_sname varchar(32) not null, school_fname varchar(255), school_admin varchar(16), school_jl varchar(255), primary key (school_id) ); /*==============================================================*/ /* Index: school_PK */ /*==============================================================*/ create unique index school_PK on school ( school_id ASC ); /*==============================================================*/ /* Table: student */ /*==============================================================*/ create table student ( student_id varchar(16) not null, school_id varchar(16), student_name varchar(16) not null, student_sex varchar(2) not null, student_birth date, student_party varchar(16), student_from varchar(32), student_addr varchar(64), student_tel varchar(32), student_head varchar(32), student_detail varchar(255), student_photo long binary, primary key (student_id) ); /*==============================================================*/ /* Index: student_PK */ /*==============================================================*/ create unique index student_PK on student ( student_id ASC ); /*==============================================================*/ /* Index: have_student_FK */ /*==============================================================*/ create index have_student_FK on student ( school_id ASC ); /*==============================================================*/ /* Table: teach_teachers */ /*==============================================================*/ create table teach_teachers ( course_id varchar(16) not null, teacher_id varchar(16) not null, primary key (course_id, teacher_id) ); /*==============================================================*/ /* Index: teach_teachers_PK */ /*==============================================================*/ create unique index teach_teachers_PK on teach_teachers ( course_id ASC, teacher_id ASC ); /*==============================================================*/ /* Index: teach_teachers_FK */ /*==============================================================*/ create index teach_teachers_FK on teach_teachers ( course_id ASC ); /*==============================================================*/ /* Index: teach_teachers2_FK */ /*==============================================================*/ create index teach_teachers2_FK on teach_teachers ( teacher_id ASC ); /*==============================================================*/ /* Table: teacher */ /*==============================================================*/ create table teacher ( teacher_id varchar(16) not null, school_id varchar(16), teacher_name varchar(16) not null, teacher_sex varchar(2), teacher_birth date, teacher_level varchar(16), teacher_duty varchar(16), teacher_addr varchar(64), teacher_tel varchar(32), primary key (teacher_id) ); /*==============================================================*/ /* Index: teacher_PK */ /*==============================================================*/ create unique index teacher_PK on teacher ( teacher_id ASC ); /*==============================================================*/ /* Index: have_teacher_FK */ /*==============================================================*/ create index have_teacher_FK on teacher ( school_id ASC ); alter table choose_course add foreign key FK_CHOOSE_C_CHOOSE_CO_COURSES (course_id) references courses (course_id) on update restrict on delete restrict; alter table choose_course add foreign key FK_CHOOSE_C_CHOOSE_CO_STUDENT (student_id) references student (student_id) on update restrict on delete restrict; alter table student add foreign key FK_STUDENT_HAVE_STUD_SCHOOL (school_id) references school (school_id) on update restrict on delete restrict; alter table teach_teachers add foreign key FK_TEACH_TE_TEACH_TEA_COURSES (course_id) references courses (course_id) on update restrict on delete restrict; alter table teach_teachers add foreign key FK_TEACH_TE_TEACH_TEA_TEACHER (teacher_id) references teacher (teacher_id) on update restrict on delete restrict; alter table teacher add foreign key FK_TEACHER_HAVE_TEAC_SCHOOL (school_id) references school (school_id) on update restrict on delete restrict;

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧