---
title: "SQL 实用技巧"
author: "wlhx"
date: "2013-10-24T12:47:55Z"
tags: ["SQL"]
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2013-10-24T12:47:55Z"
id: 1963784
url: "https://wlhx.iteye.com/blog/1963784"
---

SQL实用技巧积累如下：
```SQL

--1.查询某个数据库中总共有几张表
SELECT COUNT(id) AS COUNT FROM sysobjects s WHERE s.xtype='u'

--2.查询每张表对应的列的个数
SELECT S.NAME AS TableName,COUNT(C.ID) ColCount FROM syscolumns C
LEFT JOIN sysobjects S
ON C.id=S.id
WHERE S.xtype='u'
GROUP BY C.id,S.NAME

```