.sql为扩展名的文件导入到SQL server中出错怎么改

.sql为扩展名的文件导入到SQL server中出错怎么改,第1张

第一句应该是要判断 如果系统中没有smsdb就创建数据库smsdb吧?
应该是这样写的
if not exists(select from sysdatabases where name='smsdb')
go
create database smsdb
或者更严谨一点 就要这样写
if exists(select from sysdatabases where name='smsdb')
drop database smsdb
go
create database smsdb
还有就是你没有加批处理语句
要在每个create语句前面加上go

库A 库B要再一个服务器上
use 库B
insert into 库AC (select from c01 union all
select from c02 union all
select from c03 union all
select from c04 union all
select from c05 union all
一直到
select from c30 union all
select from c31 )
你的库真垃圾

首先要检查你的表与表之间是不是有约束(主外键约束),如果存在,才可以像 上面这位朋友的方式进行连接,一般连接有左连接、右连接、内连接,下面给你举例:
----做笛卡尔积
select sid,sname,scid,scsname,scscore from infom s ,score sc
------内连接 写法一
select sid,sname,scid,scsname,scscore
from infom s ,score sc inner join score sc
on sid= scid ------内连接的条件
------on sid <>scid --------是全集 - 交集
------where scscore>80
------内连接 方法二
select sid,sname,scid,scsname,scscore
from infom s ,score sc
where sid= scid
------
-------------------------------------------------------外连接 左连接
--------------左表数据完全显示,右表中相同的数据显示,不同数据null
select Studentname,scorescore
from Student left join score -----------------先写的为左表
on Studentid=score id -----------------连接条件
-------------------------------------------------------外连接 右连接
--------------右表数据完全显示,左表中相同的数据显示,不同数据显示null
select Studentname,scorescore
from Student right join score
on Studentid=score id
-------------------------------------------------------全连接 full join
-------------------------------------------------------左、右表的数据完全显示,相同的数据显示一次
select Studentname,scorescore
from Student full join score
on Studentid=score id
-------------------------------------------------------交叉联接
------------------------------------------交叉联接得到的是两表联接所有的数据组合
------------------------------------------(A表的数据记录 B 表的数据记录)
-------------------------------------------方式一
select Student,score from Student,score
-------------------------------------------方式二
select score ,Student from Student
cross join score
-----------------------------------------------------多表联接
--------------------------------------要求查出张三 C#的考试成绩,涉及student,score,subject三个表
---------方式一:
select studentname,subjectsname ,score score
from Student
inner join score
on studentid= scoreid
inner join subject
on scoreid=subjectid
where Studentname='张三' and subjectsname='C#'
---------方式二:等值联接
select studentname,subjectsname ,score score
from Student,score ,subject
where StudentDBid=scoreid and score id=subjectid
and Studentname='张三' and subjectsname='C#'


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13440292.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-06
下一篇 2023-08-06

发表评论

登录后才能评论

评论列表(0条)

保存