A. 求完整sql 2000代码,从创建数据库开始 规范一点
1.附加数据库:sp_attach_db 'dbname','.mdf path','.ldf path'
单文件附加: sp_attach_single_file_db [ @dbname = ] 'dbname'[ @physname = ] 'physical_name'
2.分离数据库:sp_detach_db 'dbname'
3.备份数据库:backup database dbname to disk='.bak path'
--a.创建设备 exec sp_admpdevice 'disk','diskname','.bak path'
--b.开始备份 backup database dbname to diskname
--c.删除备份设备 sp_dropdevice 'diskname'
4.还原数据库:restore database dbname from disk='.bak path'
# restore database Study from disk='.bak path'
with move 'Study' to 'd:\Data\Study.mdf'
move 'Study_log' to 'd:\Data\Study.ldf'
5.创建数据库:创建数据库Student的语句:
CREATE DATABASE Student
ON
(NAME = 'Student_dat',
FILENAME = 'D:\data\Student_dat.mdf')
LOG ON
(NAME = 'Student_Log',
FILENAME = 'D:\data\Student_Log.ldf ') 或者
CREATE DATABASE Student
ON
(NAME = 'Student_dat',
FILENAME = 'D:\data\Student_dat.mdf') 或者
CREATE DATABASE Student
6.修改数据库名称:alter database dbname modify name=newdbname
或者 sp_renamedb olddbnme,newdbname
修改数据库逻辑名:alter database Study modify file (name=Study,newname=Study_dat)
alter database Study modify file
(name=Study_log,newname=Study)
7.修改表名称:#sp_rename oldtablename,newtablename(需表的所有者才 能修改)
修改列名: #sp_rename 'temp_1.co1','co3','column'(注意'')
修改表: a.修改列类型 alter table tablename alter column 列名 类型
b.删除列 alter table tablename drop column 列名
c.增加列 alter table tablename add column 列名 类型
d.删除表Student的主键并添加
use Study
go
sp_helpconstraint Student
alter table Student drop constraint PK__Student__22AA2996
alter table Student add primary key(Sname)
清空表内容:清空表内容 truncate table Student_vice
B. sql一张表中的数据对应其他三张表的数据要怎么一下子查询出来
sql一张表中的数据对应其他三张表的数据要怎么查询出来,操作方法如下。
设备:联想电脑
系统:win8
软件:sql5.14
1、首先打开软件之后,用select语句,查看两个表中的数据,确认下来的结果是每个表中都只有两行数据。
C. sql程序代码
-----------Mx=10,y=10
ifnotexists(select1fromMwherex=10andy=10)
begin
insertintoM
select10asx,10asy,'A'ast
selectt
fromM
wherex=10andy=10
end
else
begin
---下面的这个赋值查询必须是一行结果才可以
declare@Rltvarchar(10)
select@Rlt=t
fromM
wherex=10andy=10
if(@Rlt=Aor@Rlt=0)
begin
select@Rlt
end
if@Rlt=1
begin
selectt
fromA
wherex=10andy=10
end
if@Rlt=2
begin
selectt
fromB
wherex=10andy=10
end
if@Rlt=2
begin
selectt
fromB
wherex=10andy=10
end
if@Rlt=3
begin
selectt
fromC
wherex=10andy=10
end
end
D. 急求解SQL完整代码:检索出只选择1号课程的学生信息(用Exists)
select*from 学生表 where
exists (select*from 选课表 where 课程号=1 and 学号=学生表.学号)
and not exists(select*from 选课表 where 课程号>1 and 学号=学生表.学号)
E. SQL语句代码谢谢了
首先先要明白什么是inner join:
jion 分为内连接,外连接,(其中包括 左右外连接 和 全外连接)
内连接 : select A.* from A inner join B on A.id = B.id
外链接: select A.* from A full outer join B on A.id = B.id
表A
id name
1 张
2 李
3 王
表B
id address A_id
1 北京 1
2 上海 3
SQL语句如下:
select A.name,B.address from
A inner join B
on A.id = B.A_id
查询结果为:
张 北京
王 上海
F. sql 数据库代码
是按年龄吗?
代码如下:
select sex from t_student order by age desc
上面是按照从大到小的顺序排列的,如果只要最大的话,需改成
select top 1 sex from t_student order by age desc
最小的是:
select top 1 sex from t_student order by age asc
G. 完整sql代码,有教师表,课程表,是多对多关系,还有一个教师-课程表
selectc.id,a.name,b.name
fromteachera,classb,教师-课程表cwherea.id=c.teacheridandb.id=c.classidandc.id=2
教师课程表你换下你库里的名字吧
H. 求VB数据库SQL查询在DATAGRID显示结果的完整代码
'工程-部件
'Microsoft ADO Data Control...
'Microsoft DataGrid Control 6.0
Private Sub Form_Load()
Adodc1.ConnectionString = "Driver={SQL Server};DataBase=test;Server=(local);UID=sa;PWD=123"
Adodc1.RecordSource = "select * from ask_info"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
上面代码是以sql server数据库为例的
test是数据库名,sa是用户,123是密码
如果数据库是access的,那么:
Adodc1.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\a.mdb"
I. 急求解SQL完整代码:检索出起码上过两个教师课程的学生
select * from 学生表 where (select count(教师) from 课程表
where 课程号 in (select 课程号 from 选课表 where 选课表.学号=学生表.学号))>=2
查询结果:
学号 姓名 性别 班级 年龄
1031231 张小燕 F GZ02电气2 21
1031232 张张 F GZ02电气2 21