当前位置:首页 » 编程语言 » ant执行sql

ant执行sql

发布时间: 2025-09-01 03:34:21

‘壹’ 请教高手在sql里in,all,any,some的区别和具体应用范围

给你些例子:
in 是 确定集合的

SELECT au_lname, state
FROM authors
WHERE state IN ('CA', 'IN', 'MD')
结果:
au_lname state
-------- ----
Yokomoto CA
DeFrance IN
Stringer CA
MacFeather CA
Karsen CA
Panteley MD
Hunter CA

all 是查询还可以是子查询
如:

select name from edit
其中name前省略了all.
name前可以加ALL|DISTINCT
all是所有记录.
distinct是不重复的。

带【any】的嵌套查询和【some】的嵌套查询功能是一样的。早期的SQL仅仅允许使用【any】,后来的版本为了和英语的【any】相区分,引入了【some】,同时还保留了【any】关键词。
any:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >any(select sal from scott.emp where job='MANAGER');
带any的查询过程等价于两步的执行过程。
(1)执行“select sal from scott.emp where job='MANAGER'”
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 or sal>2850 or sal>2450;

some:
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =some(select sal from scott.emp where job='MANAGER');

带some的嵌套查询与any的步骤相同。
(1)子查询,执行“select sal from scott.emp where job='MANAGER'”,其结果如图4.22所示。
(2)父查询执行下列语句。
―――――――――――――――――――――――――――――――――――――
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =2975 or sal=2850 or sal=2450;

‘贰’ 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
);

‘叁’ SQL如何为列增加日期约束

可按如下语句加约束:

altertable表名addconstraintCK_Datecheck(日期字段betweencast('1900-1-1'asdatetime)andcast('2990-1-1'asdatetime))

check约束简介:

数据库中,CHECK 约束是指约束表中某一个或者某些列中可接受的数据值或者数据格式。例如,可以要求 authors 表的 postcode 列只允许输入六位数字的邮政编码。

CHECK 约束可以应用于一个或者多个列,也可以将多个CHECK 约束应用于一个列。

当除去某个表时,对这个表的CHECK 约束也将同时被去除。

热点内容
安卓如何安装filmicpro 发布:2025-09-01 07:57:30 浏览:808
简单家用电脑服务器 发布:2025-09-01 07:52:29 浏览:691
qq收藏表情缓存缩略图 发布:2025-09-01 07:42:43 浏览:63
新电脑的密码是什么 发布:2025-09-01 06:48:53 浏览:819
照片门事件ftp 发布:2025-09-01 06:46:34 浏览:153
如何搭建tls加密服务器 发布:2025-09-01 06:46:32 浏览:701
php获取毫秒的时间戳 发布:2025-09-01 06:26:06 浏览:818
vscodephp语音怎么编译 发布:2025-09-01 06:12:26 浏览:877
pda改服务器地址在哪改 发布:2025-09-01 05:55:56 浏览:963
路人甲脚本 发布:2025-09-01 05:21:38 浏览:583