最近用到的 sql sever 语句

最近用到的 sql sever 语句

  • 查看表结构:
    sp_help 表名

  • 建表

create table 表名
(
    id int identity(1,1) primary key,--identity(1,1)设置增长率,primary key设置主键
    name nvarchar(50) not null,
    age int not null
)
  • 删除表中的数据, 表还在
delete from 表名
  • 清空表中数据, 重置表中数据
    truncate table 表名

delete会产生很多的日志(表中有多少数据, 就产生多少日志), 如果是 truncate 就会产生一行日志

  • 直接删表, 彻底删除 表不存在了
    drop table 表名
  • 查看数据
    select * from 表名 where 字段=值

  • 修改数据
    UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值

  • 增加语句
    insert into 表名(列名) values(对应的值)
    insert into Db(name, age) values('admin, 123')

  • 删除
    delete from 表名
    delete from 表名 where 字段=值

  • 查看所有表名:
    select name from sysobjects where xtype='u'

  • 查看所有表名, 和每个表中的行数

select schema_name(t.schema_id) as [Schema], t.name as TableName,i.rows as [RowCount]
from sys.tables as t, sysindexes as i
where t.object_id = i.id and i.indid <=1
  • SQL Server中统计每个表行数的快速方法

  • 查看所有表名 和表的一些基本信息
    select * from sys.tables

  • 查询所有用户定义表
    select * from sys.objects Where type='U' And type_desc='USER_TABLE'

  • 用户定义表个数
    select Count(0) as '用户定义表的个数' from sys.objects Where type='U' And type_desc='USER_TABLE'

  • SqlServer查询某个数据库中表的数量?

  • SQLServer基本操作

你可能感兴趣的:(最近用到的 sql sever 语句)