当前位置:首页 » 编程语言 » sqlserver2000语句
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sqlserver2000语句

发布时间: 2022-08-22 13:00:17

A. 求sql server 2000查询语句

create database student; //先建立个数据库
create table s //学生表s
(学号 char(12),
姓名 varchar(20),
性别 char(2),
年龄 int,
班级 char(20));

create table k //课程表k
(课号 char(12),
课名 varchar(20),
工号 int);

create table c //成绩表c
(学号 char(12),
课号 varchar(20),
成绩 int);

create table t //教师表t
(工号 char(12),
姓名 char(10),
性别 char(2),
出生日期 datetime,
职称 char(8)
);

然后最近填入数据,

1.select 课名,avg(成绩)
from K,C
where K.课号=c.课号
group by 课名

2.select 姓名,成绩
from S,C c1,K
where s.学号=c1.学号 and c1.课号=k.课号
and k.课名='英语' and 成绩 =(select max(成绩) from c where 课号=c1.课号)

create table d //读者表d
(借书证号 char(12),
姓名 varchar(20),
性别 char(2),
电话 int,
部门号 char(20));

create table t //图书表t
(书号 char(12),
书名 varchar(20),
定价 int);

create table j //借阅表j
(借书证号 char(12),
书号 varchar(20),
借书日期 dayetime,
还书日期 dayetime);

create table b //部门表b
(部门号 char(12),
部门名 varchar(20),
电话 int,
负责人 varchar(20),
人数 int);

然后最近添入数据;

3.select 姓名,部门名,(select count(*) from j where 借书证号=d.借书证号)
from d,b
where d.部门号=b.部门号
4.
select 借书证号,num
from (
select 借书证号,count(*) num
from j
group by 借书证号) a
where num =(
select max(num) from (select count(*) num from j)
)

好了,这里面有的你关键字还有外键 没跟我说 所以我没法写出来,如果有问题在跟我说

B. sql server 2000 查询语句

select top 3 * from (select top 6 * from tablename order by id asc) as t order by id desc

C. SQL server 2000 常用语句 跪求!

insert into 表名(列名,列名...) values(值,值..)--列名可选,不填默认按顺序将值填充
update 表名 set 列=值 where 条件
delete from 表名 where 条件
select * from 表名 where 条件
最基础了

D. sql server 2000 新建表的SQL语句

--if exists(select name from sysobjects where name='Table' and xtype='p')

if exists (select * from sysobjects where id = object_id(N'Table') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table Table --Table 为表名

create table Table(
字段名 类型[primary key][not null]
[constrant],
...
...
)

这只是最基本的建表语句,如果其它要求请查看SQL中建表的完整语句。
附SQLServer2005建表完整语句:
CREATE TABLE
[ database_name . [ schema_name ] . | schema_name . ] table_name
( { <column_definition> | <computed_column_definition> }
[ <table_constraint> ] [ ,...n ] )
[ ON { partition_scheme_name ( partition_column_name ) | filegroup
| "default" } ]
[ { TEXTIMAGE_ON { filegroup | "default" } ]
[ ; ]

<column_definition> ::=
column_name <data_type>
[ COLLATE collation_name ]
[ NULL | NOT NULL ]
[
[ CONSTRAINT constraint_name ] DEFAULT constant_expression ]
| [ IDENTITY [ ( seed ,increment ) ] [ NOT FOR REPLICATION ]
]
[ ROWGUIDCOL ] [ <column_constraint> [ ...n ] ]

<data type> ::=
[ type_schema_name . ] type_name
[ ( precision [ , scale ] | max |
[ { CONTENT | DOCUMENT } ] xml_schema_collection ) ]

<column_constraint> ::=
[ CONSTRAINT constraint_name ]
{ { PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
[
WITH FILLFACTOR = fillfactor
| WITH ( < index_option > [ , ...n ] )
]
[ ON { partition_scheme_name ( partition_column_name )
| filegroup | "default" } ]
| [ FOREIGN KEY ]
REFERENCES [ schema_name . ] referenced_table_name [ ( ref_column ) ]
[ ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
[ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
[ NOT FOR REPLICATION ]
| CHECK [ NOT FOR REPLICATION ] ( logical_expression )
}

<computed_column_definition> ::=
column_name AS computed_column_expression
[ PERSISTED [ NOT NULL ] ]
[
[ CONSTRAINT constraint_name ]
{ PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
[
WITH FILLFACTOR = fillfactor
| WITH ( <index_option> [ , ...n ] )
]
| [ FOREIGN KEY ]
REFERENCES referenced_table_name [ ( ref_column ) ]
[ ON DELETE { NO ACTION | CASCADE } ]
[ ON UPDATE { NO ACTION } ]
[ NOT FOR REPLICATION ]
| CHECK [ NOT FOR REPLICATION ] ( logical_expression )
[ ON { partition_scheme_name ( partition_column_name )
| filegroup | "default" } ]
]

< table_constraint > ::=
[ CONSTRAINT constraint_name ]
{
{ PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
(column [ ASC | DESC ] [ ,...n ] )
[
WITH FILLFACTOR = fillfactor
|WITH ( <index_option> [ , ...n ] )
]
[ ON { partition_scheme_name (partition_column_name)
| filegroup | "default" } ]
| FOREIGN KEY
( column [ ,...n ] )
REFERENCES referenced_table_name [ ( ref_column [ ,...n ] ) ]
[ ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
[ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
[ NOT FOR REPLICATION ]
| CHECK [ NOT FOR REPLICATION ] ( logical_expression )
}

<index_option> ::=
{
PAD_INDEX = { ON | OFF }
| FILLFACTOR = fillfactor
| IGNORE_DUP_KEY = { ON | OFF }
| STATISTICS_NORECOMPUTE = { ON | OFF }
| ALLOW_ROW_LOCKS = { ON | OFF}
| ALLOW_PAGE_LOCKS ={ ON | OFF}
}

一个简单建表例子:
CREATE TABLE films (
code char(5) CONSTRAINT firstkey PRIMARY KEY,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
);

E. sql server 2000 查询语句怎样写

SQL语句写法很多,优化程度也不同,给你最容易看懂的写法

查询
select * from Tickets_Sale a,Ticket_Retu b,Ticket_Del c where a.D_DelOperTime=b.D_DelOperTime and b.D_DelOperTime=c.D_DelOperTime and c.D_DelOperTime='2009-04-29'

统计条数(比上面多了个count() 很直接的把*统计)
select count(*) from Tickets_Sale a,Ticket_Retu b,Ticket_Del c where a.D_DelOperTime=b.D_DelOperTime and b.D_DelOperTime=c.D_DelOperTime and c.D_DelOperTime='2009-04-29'

F. 解释 SQLserver2000 中的语句 谢谢

Employee,Department
,Wages是3个表。
他们的连接方式是内连接(inner join),等同于 join。
on 后面表示连接条件。

Employee,Department两个表的连接条件是:
Employee.DepartmentNum = Department.DepartmentNum
Department ,Wages两个表的连接条件是:
Employee.EmployeeNo = Wages.EmployeeNo
以上语句就相当于:
create view EmployeeVIEW
as
select Employee.EmployeeNo,Employee.Name,
Employee.Grade,Employee.DepartmentNum,
Employee.Position,Department.DivisionalManager,
Wages.RealWages
from Employee,Department,Wages
where
Employee.DepartmentNum = Department.DepartmentNum and
Employee.EmployeeNo = Wages.EmployeeNo

G. 关于SQL SERVER2000的语句执行。

你先右键执行一个查询,快捷菜单上面会出现一个SQL字样的图标的,在那上面执行就好了.或者你直接使用查询分析器执行语句也行.
V是SQL界面里的一个红色小勾勾

H. 求一些关于sqlserver2000 的一些基本的语句例子

Select [ALL | DISTINCT] [TOP n] <select_list> select_lisit: 字段列表,* 就是所有的字段 All : 系统默认,列中所有内容 Distinct: 列中有相同内容只显示一个,Null值被认为是相同的值 Top n[PERCENT]: 返回top n行 如果PERCENT关键字指定的话则返回前百分之n行数据 Select from 语句 From {<table_source>}[,..,n] from后面用到表,视图这些数据表(源) 多个表可以用,号隔开. From 还可以指定表或者视图之间联接的类型,这些类型将决定于on子句中指定的联接条件 SELECT a.*,p.pub_id,p.pub_name,p.country FROM authors AS a INNER JOIN publishers AS p ON a.city=p.city Select where 语句 where 是条件查询语句: 比较运算符:<,<=,>,>=,=,>,<,!=,!<,!> 范围说明: Between 10 and 50 , not Between 1980-04-09 and 1980-10-09 , 数字时间都可以 可选值列表: in, not in 模式匹配: Like, not Like 是否空值: is null, is not null 条件的逻辑组合: And,or,not 注意: text,ntext,image这些类型字段不能和比较运输符组成条件查询语句 范围说明: select * from temp where id Between 10 and 50 可选值列表:select * from temp where city in ('上海','常州') 模式匹配: select * from temp where city Like '%上海%' Select group by 语句 group by 字句指定查询结果的分组条件 语法如下: GROUP BY [ALL] 列名[,...n] [WITH{CUBE | ROLLUP}] ALL: 返回所有可能的查询结果, all 不能和 CUBE | ROLUP 同时使用 Select order by 语句 ORDER BY {列名或视图 [ASC| DESC]}[,...N] 对查询生成的结果集进行排序 ASC:升序 (系统默认) DESC:降序 等等

采纳哦

I. SQLSERVER2000数据库的查询语句怎么写

搂主说得不是太明白,你是要取第一条记录所对应的那个时间吗?
如果是的话,用如下语句即可。

select min(time)
from table1
group by convert(varchar(13),time,20)

假设Table1表中数据如下

2006-05-01 11:01:00.000
2006-05-01 11:02:00.000
2006-05-01 12:02:00.000
2006-05-02 12:02:00.000
2006-05-02 12:01:00.000

查询结果为:
2006-05-01 11:01:00.000
2006-05-01 12:02:00.000
2006-05-02 12:01:00.000

对应的都是每小时中最早的那一条时间。

convert(varchar(13),time,20)
的意思是将time字段转换成字符串形式,convert的第三个参数,取值20是将时间转换成yyyy-mm-dd hh:mm:ss的形式。由于限定了是转换成长度为13的字符串,所以转换后就会取时间字符串的前13位yyyy-mm-dd hh