SQL Server 一些操作语句

查询表结构---sp_help 表名 或 sp_columns  表名

删表 -------drop table 表名
删表中所有的数据----------truncate table 表名
根据条件删表中的数据 -----delete from 表名 where 条件

增加字段:alter table 表名 add 字段名 数据类型 not null default 0

删除字段:alter table 表名 drop column 字段名;

修改字段长度:alter table 表名 alter column 字段名 类型名(长度)

删除主键:

1、先找主键的约束名称:查询表结构 (sp_help 表名 ) ---- 找约束名 ( constraint_name )

2、在删除:alter table 表名 drop constraint 约束名

去重 ---- distinct 字段
select distinct userclass from s_tablelist -- or - - select userclass from s_tablelist group by userclass having COUNT(userclass)>0 {select * from s_tablelist where userclass in (...)}

插入数据
insert into tablename(...字段名...)
select ...对应的值...

可用union 连接多条要插入的数据

如:

insert into Student(S_StuNo,S_Name,S_Sex,S_Height)
select '003','博客','M','178' union 
select '005','作者','F','175'

需要修改sqlserver数据库中某一字段的值,例如从“1234560001”至“1234560999”的字段supplier_id进行修改,要求修改后的supplier_id字段值为“654321****”。

可以使用replace()函数进行修改:update  table  set  supplier_id=replace(supplier_id,'123456','654321') where supplier_id like '123456%';

 

转载于:https://www.cnblogs.com/zzy567/p/9151432.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值