SQL中的Table,View。。。
来源:互联网 发布:捕鱼源码 编辑:程序博客网 时间:2024/06/15 02:34
Table,表是一种数据库中的物理存在。
View,视图只是一个虚拟的存在,是一个预编译的sql select语句。视图可以组合多个表组成一个sql语句,可以显示一些字段,可以不显示一些字段,这样视图就做到了安全性。
参考:http://myitforum.com/myitforumwp/2011/10/21/sql-101-whats-the-difference-between-tables-and-views-or-views-and-tables/
A common theme I seem to be getting from people in the SMS/SCCM forums is possibly a misunderstanding of the difference between tables and views. I don’t wish to project in any way like I’m talking down to anyone or that I think I’m better than anyone with this post. There are people who I consider to be twice the engineer that I am who are awesome SMS guys, but who hold some misconceptions about the SQL side of things. There are others who are just starting out and are looking for anyone who will stop and help them out with the basics without talking way over their head. So, if you all don’t mind I’d like to clarify some things for people in any of those camps who might need clarification about tables and views.
I think pretty much everyone understands the basics with Excel workbooks/spreadsheets (or the Open Office equivalent to Excel) , so I’d like to use that analogy to help explain the difference between tables and views. It’s not a perfect analogy because SQL is SOOO much more than Excel, but I think it’s close enough to illustrate the point and enough people use it to make it the best example I can think of.
So first, think of an Excel workbook
Inside that workbook may be multiple worksheets with their own name
Inside each worksheet are columns across the top and rows down the left
Where the rows and columns come together are called cells
The cells physically hold data that’s used for all kinds of purposes.
Now, think of a SQL database as an Excel workbook.
Inside that database is a bunch of tables, each table is like a different worksheet in the workbook
Inside each table are a bunch of fields/columns, each field/column is like a column in the worksheet
When you insert data into the fields, they are physically inserted into new rows like you enter stuff into cells in the spreadsheet.
As for views…think about that workbook again. If you create a new worksheet and then start putting formulas in the cells that reference cells in other worksheets, it’s now like a SQL view. The data isn’t physically stored in this new worksheet, it’s stored in the cells of the other worksheets, but you are able to see and combine the data from a bunch of different cells in one spot and manipulate it however you want. This is what a view is like. A view doesn’t store the data, it’s just a way to get and/or combine the data that’s already stored somewhere in the DB and you can use different column names.
More than one person has asked how to dynamically create views from SMS web reports or from within their query and then delete them when they’re done. If you now think of a view as a worksheet that doesn’t store the data, but just links to other data you can imagine it wouldn’t make much sense to create a new worksheet on the fly, fill the cells with formulas to get the data from the other worksheets, do something with that data, and then remove the sheet. It would make more sense to create this new worksheet, fill the cells with formulas to get data from the other worksheets and then save it so it can be used again and again. It’s the same thing with a view, you create it, reference tables or even other views, and then save it.
So in summary, tables hold the physical data and views just link to that data. Of course, there’s so much more to tables and views than I’m explaining here, but I don’t want to overwhelm anyone with information if you’re not really going to use yet so I’m going to leave it at that.
Thanks for listening! As always, let me know if there’s something you’d like to have explained, or explained better.
- SQL中的Table,View。。。
- T-SQL Recipes------Table, Index, View, Function
- Sql Server中的truncate table
- sql: table,view,function, procedure created MS_Description in sql server
- sql: table,view,function, procedure created MS_Description in sql server
- Table View
- table View
- SQL Programming(5):Presenting Data in a Table View
- PL/SQL: ORA-00942: table or view does not exist
- Oracle中的external table和 materialized view学习
- iOS学习- 13 删除Table View中的Cell - Todo App
- iOS学习- 14 增加Table View中的iteml - Todo App
- Android 自定义View 常用菜单的中的Table
- sql table
- SQL table
- Delegates in table view
- 13 Table View javafx
- IOS table view 使用
- lpc175416K的内部ram,16K的AHB SRAM
- eclipse maven plugin execution not covered by life cycle configuration
- Linux内核源码:Kconfig和Makefile
- Android红外摇控与remote.conf
- 小巧Linux发行版本,老机器也不愁
- SQL中的Table,View。。。
- 使用七牛CDN为博客加速
- 初始化SDRAM
- 【discuzx2】关于discuz模板文件中注释所导致的问题
- android overridePendingTransition()使用(切换activity动画实现)
- eclipse打断点调试进入到class文件中--解决方法
- df 磁盘空间查看命令
- MySQL导入sql 文件的5大步骤
- VS2010与System.Data.OracleClient