最近用到的 sql sever 語(yǔ)句
查看表結(jié)構(gòu):
sp_help 表名
建表
create table 表名
(
id int identity(1,1) primary key,--identity(1,1)設(shè)置增長(zhǎng)率,primary key設(shè)置主鍵
name nvarchar(50) not null,
age int not null
)
- 刪除表中的數(shù)據(jù), 表還在
delete from 表名
- 清空表中數(shù)據(jù), 重置表中數(shù)據(jù)
truncate table 表名
delete會(huì)產(chǎn)生很多的日志(表中有多少數(shù)據(jù), 就產(chǎn)生多少日志), 如果是 truncate 就會(huì)產(chǎn)生一行日志
- 直接刪表, 徹底刪除 表不存在了
drop table 表名
查看數(shù)據(jù)
select * from 表名 where 字段=值
修改數(shù)據(jù)
UPDATE 表名稱 SET 列名稱 = 新值 WHERE 列名稱 = 某值
增加語(yǔ)句
insert into 表名(列名) values(對(duì)應(yīng)的值)
insert into Db(name, age) values('admin, 123')
刪除
delete from 表名
delete from 表名 where 字段=值
查看所有表名:
select name from sysobjects where xtype='u'
查看所有表名, 和每個(gè)表中的行數(shù)
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
查看所有表名 和表的一些基本信息
select * from sys.tables
查詢所有用戶定義表
select * from sys.objects Where type='U' And type_desc='USER_TABLE'用戶定義表個(gè)數(shù)
select Count(0) as '用戶定義表的個(gè)數(shù)' from sys.objects Where type='U' And type_desc='USER_TABLE'