第1个回答 推荐于2017-09-19
--创建table 1
create table t1
(
BH nvarchar(2) not null,
TNAME NVARCHAR(20),
SEX NVARCHAR(2)
)
--插入数据
INSERT INTO T1(BH,TNAME,SEX)
SELECT '01','张三','男' union all
select '02','李四','男' union all
select '03','王五','女'
--创建 table 2
create table t2
(
BH nvarchar(2) NOT NULL,
DZ NVARCHAR(40),
ZW NVARCHAR(40)
)
--插入数据
INSERT INTO T2(BH,DZ,ZW)
SELECT '01','西环路','学生' union all
select '02','东环路','工程师' union all
select '03','南环路','总经理'
/* SQL语句1 */
SELECT T1.BH,T1.TNAME,T1.SEX,T2.DZ,T2.ZW FROM T1,T2
WHERE T1.BH=T2.BH
/*方法二*/
SELECT T1.BH,T1.TNAME,T1.SEX,T2.DZ,T2.ZW
FROM T1 inner join T2
on T1.BH=T2.BH
--删除两个表
DROP TABLE T1
DROP TABLE T2