---
title: "sqlserver常用的语句"
author: "mywebcode"
date: "2012-11-05T20:16:00Z"
tags: []
slug: "sqlserver"
draft: false
lastmod: "2013-05-08T10:26:30Z"
id: 1862869
url: "https://mywebcode.iteye.com/blog/1862869"
---

1修改表结构：

（1）添加列：alter table 表名 add 列名 列的类型

（2）删除列：alter table 表名drop 列名

（3）修改现有项的数据类型：

alter table 表名  
alter column列名 要改成类型

（4）当表中数据中涉及到null时在where中写条件时null为不知道（例如where fname is null，where fname isnot null）

（5）count是查询记录的条数

（6）复制表结构

1：select top0 * 字段 from 表名 //top 0 没记录所以就剩表结构

2：select * from 表名 where 让命题为永远为假

（7）给表名备注是有两种方法

1：给的名字=字段 //注意顺序，错了就不对了

2：字段 as 给的名字

（8）分完组后在累加值时要用SUM（字段）