亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

創建mysql可更新視圖

標簽:
MySQL

Summary: in this tutorial, we will show you how to create an updateable view and update data in the underlying table through the view.

In MySQL, views are not only read-only but also updateable. However in order to create an updateable view, the SELECT statement that defines the view has to follow several following rules:

  • The SELECT statement must only refer to one database table.

  • The SELECT statement must not use GROUP BY or HAVING clause.

  • The SELECT statement must not use DISTINCT in the column list of the SELECT clause.

  • The SELECT statement must not refer to read-only views.

  • The SELECT statement must not contain any expression (aggregates, functions, computed columns…)

When you create updateable views, make sure that you follow the rules above.

Example of creating updateable view

Let’s practice with an example of creating an updateable view.

First, we create a view named officeInfo against the offices table. The view refers to three columns of the offices table:  officeCodephone and city.

CREATE VIEW officeInfo  AS     SELECT officeCode, phone, city    FROM offices

Next, we can query data from the officeInfo view using the SELECT statement.

SELECT * FROM officeInfo

Then, we can change the phone number of the office with officeCode 4 through the officeInfo view by using the 

Finally, to see the change, we can select the data from the officeInfo view by executing following query:

SELECT * FROM officeInfo WHERE officeCode = 4

In this tutorial, we have shown you how to create an updateable view and how to update data in the underlying table through the view.

Related Tutorials

原文链接:http://outofmemory.cn/mysql/view/create-sql-updatable-views

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消