SQL Server语句大全(增删改查数据、创建表、删除表、修改表)
生活随笔
收集整理的這篇文章主要介紹了
SQL Server语句大全(增删改查数据、创建表、删除表、修改表)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SQL server 增刪改查語句
新增
insert into test.dbo.users (id,username,password) values(1,'lisi',123),(2,'lisi',123);insert into test.dbo.users (id,username,password) -- 將查詢結果插入 select * from test.dbo.users;刪除
delete test.dbo.users where id=1修改
update test.dbo.users set username='aaa' where id=1;查詢
select distinct * from test.dbo.users; -- 去重 select top 3 * from test.dbo.users; -- 前n行表操作
創建表
create table teacher(id int primary key,name varchar(10) not null,age int)刪除表
drop table teacher;修改表
alter table teacher -- 添加字段 add name varchar(10) not null;alter table teacher -- 刪除字段 drop column name;exec sp_rename 'teacher.name','newname','COLUMN'; -- 修改字段alter table teacher -- 修改字段類型 alter column name varchar(10) not null;SQL server 查詢語句
基礎查詢
select * from test.dbo.users -- 普通條件查詢 where id=1;模糊查詢
select * from test.dbo.users where username like '%li%';范圍查詢
select * from test.dbo.users -- id在1~3之間的數據 where id between 1 and 3;select * from test.dbo.users -- id在1~3以外的數據 where id not between 1 and 3;子查詢
select * from test.dbo.users -- id為1或2或3的數據where id in(1,2,3);select * from test.dbo.users -- id不是1或2或3的數據where id not in(1,2,3);排序
select * from test.dbo.users -- 從小到大排序 order by id asc;select * from test.dbo.users -- 從大到小排序 order by id desc;整篇文章是整個SQL Server基礎的操作語句,熟練掌握即可基本進行維護與實施工作。
總結
以上是生活随笔為你收集整理的SQL Server语句大全(增删改查数据、创建表、删除表、修改表)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL注入(SQL注入(SQLi)攻击)
- 下一篇: C#反射使用方法过程及步骤