Create SQL View, Delete View
These commands add and remove both local and remote views from a database. CREATE SQL VIEW is rather long-winded, but it must be, because CREATE VIEW is an old (useless) Xbase command.
Usage |
CREATE SQL VIEW [ ViewAlias ] [ REMOTE ] [ CONNECTION Connection [ SHARE ] | CONNECTION DataSource ] [ AS SQLSelect ] |
Parameter |
Value |
Meaning |
ViewAlias |
Name |
The name to assign the new view. |
Omitted |
If the AS clause is also omitted, open the View Designer for a new view. Otherwise, FoxPro prompts for a name for the new view. |
|
Connection |
Name |
The name of an existing connection in the database that should be used to access remote data. |
DataSource |
Name |
The name of an existing ODBC data source that should be used to access remote data. |
SQLSelect |
Included |
Define the view to use the specified query. |
Omitted (along with the AS keyword) |
Open the View Designer for a new view. |
Although CREATE VIEW FileName creates FileName.VUE, CREATE VIEW alone brings up the View Designer. So, don't fret about being confused over these two commands; it appears Microsoft is confused, too! |
Parameterized views can't be accessed from the VFP OLE DB provider, new in VFP 7. If you try to open a parameterized view through the provider, you get a "SQL column parameter name not found" error. Creating an ADO Parameter object with the proper name and value doesn't help. The reason for this problem is that the way VFP handles parameters is incompatible with the way OLE DB handles them. The only workaround is to issue the SQL SELECT command that the view uses as a query to the provider. |
Example |
CREATE SQL VIEW EmployeesByBirthDate ; AS SELECT * FROM TasTrade!Employee ; WHERE Birth_Date >= ?Birthdate |
This one's really cool. When you use a parameterized view as the source for a control in a form (say, a grid or list), the parameter can be something like "ThisForm.SomeProperty." You can set up the view just as you want it on the form and not have to use a separate variable for the parameter. When you open the view outside the form, you get prompted for the parameter just as you do in any other case. This is the only place we know of in Visual FoxPro where you can use ThisForm notation in something other than method code or a property definition. Here's an example, letting you filter Employee on country. |
CREATE SQL VIEW EmpsByCountry AS ; SELECT First_Name,Last_Name FROM TasTrade!Employee ; WHERE Country = ?ThisForm.CountryIn the form that displays this view, you'd create a Country property and, perhaps, have a combo box with ThisForm.Country for a ControlSource. The combo's InteractiveChange method could REQUERY() the view and Refresh the form.In VFP 7, the CREATE SQL VIEW command fires the database's BeforeCreateView and AfterCreateView events if database events are turned on.
Usage |
DELETE VIEW [ ViewName ] |
Although Help says otherwise, you can omit ViewName and you're prompted with a list of views in the current database. Help also states that DELETE VIEW requires exclusive access to the database, but that's not true. |
Example |
DELETE VIEW EmployeesByBirthDate |
See Also |
AfterCreateView, AfterDropView, BeforeCreateView, BeforeDropView, Create Connection, Create Database, Create View, CursorSetProp(), DBSetProp(), Drop View, Select-SQL, Use |