一、创建表
create table tablename (
id int <not null >| identity(1,1) | primary key | unique ,
name varchar (20) default 'ada')
identity(1,1) 是用来定义逐渐增长的数据 ,(1,1) 第二个参数表示增长幅度,第一个表示参照于前面哪个,如1表示前面一个数的值,2则表示前面第二个数的值
二、alter table 修改表
新增加一个列
alter table tablename
add columnname type(数据类型) 如 alter table plays add pay int default '1000' 往plays中添加工资一列 默认为1000
但是若原先就含有数据,那pay设置为null , 新的数据才显示1000
最好做法就是 alter table plays add pay int default 1000 not null 有了not null 已经存在的数据就会按1000录入
select name,pay,pay*(2+500)
from plays
select name+'name' as 名字加后缀 ,pay
from plays
select distinct pay from plays
select * from plays
where pay between '2000' and '4000'
select * from plays
where pay in( '2000' , ' 5000')
select * from plays
where name like 'l%'
select * from plays
where clubId > 2
and id<7
or name like'l%' //and 的优先级 大于or
select starttime as 时间 from plays
order by 时间 desc //按别名排序
select LOWER(name) 小写 from plays
select UPPER(name) 大写 from plays
select INITCAP(name) from plays //oracle 才有INITCAP这个函数 首字母大写 其他小写
select length(pay) from plays
where pay in( '2000' , ' 5000')
select RoUND(pay,-2) 百位四舍五入
from plays
select (getdate()-starttime) as 任期
from plays
where id =5
create table player( pid int not null primary key ,
pname varchar(20),
p_cid int not null ,
ptime date default sysdate,
foreign key (p_cid) references play(cid))