insert into dbo.Customers(CustomerID,CompanyName,ContactName,ContactTitle,
Address,City,Region,PostalCode,Country,Phone,Fax) values (10008,'guoguo','zyt','1222223',
'henan','zhengzhou','jinshuiqu','412453','chianese','123566655','232323')
select * from dbo.Customers where CustomerID='10008'
create table UserTable(UserId int not null,UserName nvarchar(50),Age int null)
insert into dbo.UserTable(UserName,Age) values (N'王艳果','19')
select * from dbo.UserTable where UserId='12'
select * from dbo.UserTable
select username,age from dbo.UserTable
select username as 用户名,age+2 as 年龄 from dbo.UserTable --更换头标题
select @@versio
select count(*) from dbo.UserTable
select max(age) from dbo.UserTable
select min(age) from dbo.UserTable
select avg(age) from dbo.UserTable --平均值
select sum(age) from dbo.UserTable
drop table dbo.UserTable --删除整个表了
delete from dbo.UserTable where age=19--删除整个表中的数据
------------ALTER TABLE [ ONLY ] name [ * ] action [, ... ]
update dbo.UserTable set UserName=N'雨念' where Age=19
update dbo.UserTable set UserName=N'王艳果' where userid=20
update dbo.UserTable set UserName=N'果果' where Age>=20
update dbo.UserTable set UserName=N'张勇涛' where userID=17
update dbo.UserTable set UserName=N'张勇涛',Age=18 where userid=6 or userid=7
select top 3 * from dbo.UserTable where UserName=N'雨念'--查出前三条姓名为“雨念”的信息
select * from dbo.UserTable where 1=1
select * from dbo.UserTable where (Age<19 and age>17) or (age=20)
select 1+1 as 列,getdate() as 日期,newid() as 编号--加上头标题
select * from dbo.UserTable order by age DESC --年龄按降序排序 ASC 升序
select * from dbo.UserTable where age>16 order by age DESC,salary DESC; --年龄按降序排序 如果年龄相同则按工资的升序排列
--update dbo.UserTable set rowcount 3
select * from dbo.UserTable where UserName like '张%'--以张开头的username所有信息
select * from dbo.UserTable where UserName like '%g果%'--检索姓名中包含“果”的所有信息
select * from dbo.UserTable where age in (16,18,20,17)--年龄等于这个值的
select * from dbo.UserTable where age>17 and age<20 -- 20>年龄>17的人员信息
select age,username,count(*)as 人数 from dbo.UserTable group by age,username--分组按年龄相同且姓名也相同的人员总数
select age,count(*)as 人数 from dbo.UserTable group by age having count(*)>1 --显示总人数大于1的
select age,count(*)as 人数 from dbo.UserTable where salary>44444 group by age--工资大于44444的取出来后再计算年的人数
select top 3 * from dbo.UserTable where userid not in (select top 5 userid from dbo.UserTable order by salary desc)order by salary desc--查询按照工资从高到低排序,且 查询出此排行在第六名开始的一共三个人的信息
alter table dbo.UserTable add SubCompany varchar(20)--
往表中增加字段
alter table dbo.UserTable add Department varchar(20)queryselectorall用法
update dbo.UserTable set SubCompany=N'北京',Department=N'营销部' WHERE AGE=16
update dbo.UserTable set SubCompany=N'上海',Department=N'营销部' WHERE AGE=17
update dbo.UserTable set SubCompany=N'台湾',Department=N'营销部' WHERE AGE=18
update dbo.UserTable set SubCompany=N'北京',Department=N'技术部'
update dbo.UserTable set SubCompany=N'上海',Department=N'技术部'
update dbo.UserTable set SubCompany=N'台湾',Department=N'技术部' WHERE AGE=19
update dbo.UserTable set SubCompany=N'北京',Department=N'财务部'
update dbo.UserTable set SubCompany=N'上海',Department=N'财务部' WHERE AGE=20
update dbo.UserTable set SubCompany=N'台湾',Department=N'财务部'
select * from dbo.UserTable
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论