sql创建表
创建表方式1
create table 表名(
列名称 数据类型【default 默认值】 【【constrant 约束名】constant_def】,
列名称 数据类型【default 默认值】 【【constrant 约束名】constant_def】,
列名称 数据类型【default 默认值】 【【constrant 约束名】constant_def】
)【tablespace tablespaceName】;
constant_def:直接使用约束名,例如id varchar2(12) primary key
tablespace tablespaceName:指定表空间,如果没有指定,使用默认表空间
查询表名,表空间信息
select table_name,tablespace_name from user_tables;
create table student(
sno varchar2(10) primary key,
sname varchar2(20),
sage number(2),
ssex varchar2(5)
)tablespace ;
创建表方式2:子查询创建表
create table People as select * from student;
好处:复制student表的数据到People表中。
数据类型
char 类型:自动补空格
函数length,trim,to_date
length:获取长度
trim:去除首尾空格
to_date可以实现指定格式的日期;
to_date(‘2012-12-12’,’yyyy-MM-dd‘);
number类型:超出精度的情况
sysdate:获取当前日期
select sysdate from dual— dual是个虚表,作用让查出来的数据以表结构的形式来显示