SQL中JOIN的使用
(注:outer的意思就是"没有关联上的行"。)
1.cross join 全外连接(笛卡尔乘积)
SELECT A.*, B.* from A FULL OUTER JOIN B ON A.ID = B.ID
2.inner join 内连接(在笛卡尔乘积的结果集中去掉不符合连接条件的行)
SELECT A.* from A INNER JOIN B ON A.ID=B.ID
3.left outer join 左外连接(在inner join的结果集上加上左表中没被选上的行,行的右表部分每个字段都用NUll填充)
SELECT A.* from A LEFT JOIN B ON A.ID = B.ID
4.right outer join 右外连接(在inner join的结果集上加上右表中没被选上的行,行的左表部分全用NULL填充。)
SELECT A.* from A RIGHT JOIN B ON A.ID = B.ID
举例说明:
表A
记录如下:
aID aNum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
表B
记录如下:
bID bName
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
实验如下
:
1.left join
sql
语
相关文档:
包由包规范和包体两部分组成。
1、包规范(Package Specification)
包规范,也叫做包头,包含了有关包的内容的信息。但是,它不包含任何过程的代码。
创建包头的语法一般如下
CREATE [OR REPLACE] PACKAGE package_name {IS | AS}
Procedure_name | function_name | variable_declaration | type_def ......
--1加内存表
EXEC sp_tableoption '表名','pintable', 'true'
--2卸载内存表
EXEC sp_tableoption '表名','pintable', 'false'
--2查询是否有内存表驻留
SELECT * from INFORMATION_SCHEMA.Tables
WHERE TABLE_TYPE = 'BASE TABLE'
AND OBJECTPROP ......
Differring Constraints:
Constraints can have the following attributes: DEFFERRABLE / NOT DEFFERRABLE, INITIALLY DEFFERRED / INITIALLY IMMEDIATE.
e.g.:
alter table dept2 add constraint dept2_id_pk primary key (department_id) deferrable initially deferred; // deferring constraint on creation. ......
Merge statement
function benefits: 1) provides the ability to conditionally update, insert or delete data into a database table. 2) performs an update if the row exists, and an insert if it is a new row. --> 1) avoids seperate updates, 2) increase performance and ease of use. 3) is useful in dat ......
CREATE VIEW MYVIEW
AS
SELECT * from bjxxdiweb_database2007.dbo.bm_tongji
UNION ALL
SELECT * from aa.DBO.chen
select * into aa..chen from bjxxdiweb_database2007.dbo.bm_tongji where 1=2
说明:数据库A的表的字段名必须和数据库B的表的字段名相同,包括数据类型等。 ......