zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

详解Sql基础语法

SQL基础 详解 语法
2023-06-13 09:19:43 时间

create table 新表名称 like 旧表名称

create table 新表名称 as select 列名 from 旧表名称 defintion only

6. 增加一个列

Alter table 表名称 add 列名称 数据类型

7.添加主键

alter table 表名称 add primary key(列名称)

8.自增id属性从1开始每次加1

identity (1,1)

9.创建索引

create index 索引名 on 表名(列名)

10.删除索引

drop index idx_name

11.CTE查询

;with t as(
select openid,ROW_NUMBER()over(partition by openid order byopenid)as row
from #temp)delete t where row 1

12.case when的用法(修改表名称id,当 t 的名字不为空,则还是 t 的名字,否则变为表名称的名字,把被修改的数据输出到临时表)

update pn
set pn.id=case when t.id then t.id else pn.id end
output deleted.id into 临时表
from 表名称 pn with(nolock)
join #temp t

13.查询、插入、删除、求和、平均、最大值

select * from table
insert into new_table(id,name)values(1, 张三 )
delete from table where 范围
select sum(field1) as sumvalue from table1
select avg (field1) as avgvalue from table1
select max(field1) as maxvalue from table1

通过以上内容给大家详解Sql基础语法,希望本文介绍能够给大家带来帮助。


我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题

本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 详解Sql基础语法