Week 19
What is an SQL view. How is it similar to a table? In what ways is it different (think about primary keys, insert, update, delete operations) ?
An SQL view is a virtual table based on the results of a select query. It doesn't store the data but presents data from one or more tables. It is similar in that you can query a view using select like a regular table, it has columns/rows, and you can join, filter, or sort a view like a table. It is different in that it does not store data, just saves a query. It cannot define primary keys. Insert/Update/Delete not allowed. And cannot be indexed.
We have completed our study of SQL for this course. This is not to imply that we have studied everything in the language. There are many specialized features such as calculating rolling averages, query of spatial data (data with latitude and longitude) coordinates, and more. But take a minute to think about how SQL compares to other programming languages such as Java. What features are similar , and which are present in one language but not in the other? For example, Java has conditional if statements which are similar to SQL WHERE predicates, the SELECT clause is similar to a RETURN statement in that it specifies what data or expression values are to be returned in the query result (although it is strange that a statement should specify the RETURN as the first part of a SELECT.
Where clause is similar to an if statement. Select is similar to return statements. sum(), avg() are similar to methods/functions. The Differences is that SQL is database-focused. Java is a general-purpose language. More control in Java using if, while, for, etc. Java needs a database connection to access data, but SQL interacts directly with persistent data. SQL is for data manipulation, while Java is for application logic and control flow. They are both essential tools for the toolkit.
Comments
Post a Comment