SQL标准语法之数据库管理

/*SQL数据库管理*/
  
  create table emp
  (
  eid int,
  ename varchar(10),
  sal money
  )
  /*不可给自动增加列赋值*/
  /*列名列表要和值列表匹配*/
  /*字符类型与日期类型加单引号*/
  insert into emp(sal,ename,eid) values(1234,'rose',1001)
  
  /*删除表中数据*/
  1。drop table emp--最为彻底
  2。truncate table emp--不带日志,效率较高
  /*此两种方法不能被外键引用,不可带条件删除*/
  3。delete from emp where ...
  /*不能删除被引用的数据*/
  
  /*表重命名*/
  sp_rename 'emp','newemp'
  
  /*列重命名*/
  sp_rename 'newemp.eid','neweid','COLUMN'
  
  /*复制表结构(带数据)*/
  select * into emp from newemp--自增与NOT NULL可复制,其他约束不可
  
  /*复制表结构(不带数据)*/
  select * into emp from newemp where 1>2
  
  /*复制部分列*/
  select clo1,col2,col3 into emp from newemp
  /*上三种中emp为select自动创建新表*/
  
  /*查询指定表约束*/
  sp_helpconstraint emp
  
  /*执行指定的SQL指令*/
  sp_executesql N'select * from emp'
  /*N表示后面的字符串采用unicode编码体系(无论中英文均一字符双字节)*/
  
  /*模糊查询like*/
  
  select * from emp where eid not like '[0-8][0-8][0-12]'
  /*中括号内代表‘一’位字符的范围,[0-12]即[0-1]||[0-2]*/
  
  select * from emp where ename like 'w_'
  /*"_"通配符,代表所有字符,就是麻将里的“混”*/
  
  select * from emp where not ename='we'
  /*not不等于*/
  
  select * from emp where ename is null
  /*is null不是=null!*/
  select * from emp where ename is not null
  /*is not null不是not is null*/
  select * from emp where eid not in (2002)
  /*in 包含于*/
  select * from emp where eid between 1001 and 1002
  /*between 在两值之间的范围内取值*/  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值