---4月17日---
--使用TOP返回部分数据--
USE NorthWind
GO
---返回customers表的20%数据---
SELECT TOP 20 PERCENT *
FROM customers
GO
---由上面返回19行数据想到查询customers表共多少行数据----
---利用全局变量@@rowcount计算前面查询的行数---
USE NorthWind
GO
SELECT * FROM Customers
SELECT @@rowcount
GO
---DISINCT关键字返回不重复的数据---
---ALL与DISINCT是相对的,它返回所有行包括重复的,不过sql默认就是ALL进行查询---
USE pubs
GO
SELECT city,state
FROM authors
GO
USE pubs
GO
SELECT DISTINCT city,state
FROM authors
GO
---三种修改列名的方法及实现列的计算price减价30%---
USE pubs
GO
SELECT title_id AS '图书代号','原价'=price,price-price*0.3 '现价'
FROM titles
GO
----left(pub_id,1)取pub_id列的左边一个字符---
USE pubs
GO
SELECT pub_id,pub_name,city,state,country
FROM publishers
GO
USE pubs
GO
SELECT '999'+left(pub_id,1),pub_name+'-2',city,state,country
FROM publishers
GO
---创建视图---
USE New
GO
CREATE VIEW new_view
AS
SELECT *
FROM customer
GO
---视图的插入更新删除数据是有约束的,因为视图有可能跟多表有关系--