2.当然两个表格相互比较的栏位,其资料形态必须相同。
3.一个复杂的查询其动用到的表格可能会很多个。
整合性的查询:
SELECT COUNT (*)
FROM table_name
WHERE column_name = xxx
说明:
查询符合条件的资料共有几笔。
SELECT SUM(column1)
FROM table_name
说明:
1.计算出总和,所选的栏位必须是可数的数字形态。
2.除此以外还有 AVG() 是计算平均、MAX()、MIN()计算最大最小值的整合性查询。
SELECT column1,AVG(column2)
FROM table_name
GROUP BY column1
HAVING AVG(column2) > xxx
说明:
1.GROUP BY: 以column1 为一组计算 column2 的平均值必须和 AVG、SUM等整合性查询的关键字
一起使用。
2.HAVING : 必须和 GROUP BY 一起使用作为整合性的限制。
复合性的查询
SELECT *
FROM table_name1
WHERE EXISTS (
SELECT *
FROM table_name2
WHERE conditions )
说明:
1.WHERE 的 conditions 可以是另外一个的 query。
2.EXISTS 在此是指存在与否。
SELECT *
FROM table_name1
WHERE column1 IN (
SELECT column1
FROM table_name2
WHERE conditions )
说明:
1. IN 後面接的是一个集合,表示column1 存在集合里面。
2. SELECT 出来的资料形态必须符合 column1。
其他查询
SELECT *
FROM table_name1
WHERE column1 LIKE 'x%'
说明:LIKE 必须和後面的'x%' 相呼应表示以 x为开头的字串。
SELECT *
FROM table_name1
WHERE column1 IN ('xxx','yyy',..)
说明:IN 後面接的是一个集合,表示column1 存在集合里面。
SELECT *
FROM table_name1
WHERE column1 BETWEEN xx AND yy
说明:BETWEEN 表示 column1 的值介於 xx 和 yy 之间。
3、更改资料:
UPDATE table_name
SET column1='xxx'
WHERE conditoins
说明:
1.更改某个栏位设定其值为'xxx'。
2.conditions 是所要符合的条件、若没有 WHERE 则整个 table 的那个栏位都会全部被更改。
4、删除资料:
DELETE FROM table_name
WHERE conditions
说明:删除符合条件的资料。
说明:关于WHERE条件后面如果包含有日期的比较,不同数据库有不同的表达式。具体如下:
(1)如果是ACCESS数据库,则为:WHERE mydate>#2000-01-01#
(2)如果是ORACLE数据库,则为:WHERE mydate>cast('2000-01-01' as date)
或:WHERE mydate>to_date('2000-01-01','yyyy-mm-dd')
在Delphi中写成:
thedate= '2000-01-01';
query1.SQL.add('select * from abc where mydate>cast('+''''+thedate+''''+' as date)');
SQL Server 2000 Datatypes
By Sergey Vartanyan
Introduction
Binary datatypes
Character datatypes
Date and Time datatypes
Numeric datatypes
Integer datatypes
Monetary datatypes
Special datatypes
Text and image datatypes
Unicode Character datatypes
User-Defined datatypes
Introduction
There are three new datatypes in SQL Server 2000 in comparison with SQL Server 7.0.
These datatypes were added:
bigint
sql_variant
table
In this article, I want to tell you about built-in SQL Server 2000 datatypes, about user-defined datatypes and what datatype is generally used in a particular situation.
Binary datatypes
Binary data is similar to hexadecimal data and consists of the characters 0 through 9 and A through F, in groups of two characters each. You should specify 0x before binary value when input it.
There are two binary datatypes:
binary[(n)]
varbinary[(n)]
Binary[(n)] datatype can store up to 8000 bytes of fixed-length binary data. You can specify the maximum byte length with n.
Varbinary[(n)] datatype can store up to 8000 bytes of variable-length binary data. You can specify the maximum byte length with n. Variable-length means that binary data can contain less than n bytes, and the storage size will be the actual length of the data entered.
You should use varbinary datatype instead of binary datatype, when you expect null values or a variation in data size.
Character datatypes
Character datatypes are used to store any combination of letters, symbols, and numbers. You should enclose character data with quotation marks, when enter it.