create table person_base_info
(id int,
username varchar,
phone int
);
create table person_address
(
person_id int,
address_type varchar,
address_name varchar
);
alter table person_address alter column address_type varchar(12);
alter table person_address alter column address_name varchar(12);
alter table person_address add id int;
insert into person_base_info(id,username,phone) values(1,\'j\',135922);
insert into person_base_info values(2,\'k\',28);
insert into person_base_info values(3,\'j\',25);
insert into person_base_info values(4,\'l\',25);
select * from person_base_info
insert into person_address(id,person_id,address_type,address_name) values(1,1,\'home\',\'xixiang\');
insert into person_address(id,person_id,address_type,address_name) values(3,2,\'home\',\'xixiang\');
insert into person_address(id,person_id,address_type,address_name) values(5,3,\'home\',\'pingzhou\');
insert into person_address(id,person_id,address_type,address_name) values(2,1,\'company\',\'shengtai\');
insert into person_address(id,person_id,address_type,address_name) values(4,2,\'home\',\'changhong\');
insert into person_address(id,person_id,address_type,address_name) values(6,3,\'home\',\'keji\');
insert into person_address(id,person_id,address_type,address_name) values(7,5,\'home\',\'keji\');
select * from person_address
select addre.* from person_base_info per left join person_address addre
on per.id = addre.person_id
where per.id = 1
select * from person_base_info per right join person_address addre
on per.id = addre.person_idl
select * from person_base_info per , person_address addre
where per.id = addre.person_id
int:整型,取值范围[-231~231)
decimal:精确数值型 ,示例:decimal(8,4); //共8位,小数点右4位
money:货币型
float:近似数值型
real:近似数值型
varchar:字符型,存储非统一编码型字符数据,数据类型为变长,要指定该列的最大长度,存储的长度不是列长,而是数据的长度
text:字符型,存储大量的非统一编码型字符数据
datetime:日期时间型,从1753年1月1日到9999年12月31日间所有的日期和时间数据, 精确到三百分之一秒或3.33毫秒
cursor:特殊数据型,包含一个对游标的引用。用在存储过程中,创建表时不能用
timestamp:特殊数据型,用来创建一个数据库范围内的唯一数码, 一个表中只能有一个timestamp列,每次插入或修改一行时,timestamp列的值都会改变。
SELECT
*
FROM
表1
LEFT
JOIN
表2
ON
表1.关联字段=表2.关联字段
LEFT
JOIN
表3
ON
(表1/表2).关联字段=表3.关联字段
WHERE
条件