當前位置:首頁 » 編程語言 » 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