收藏 分销(赏)

数据库课件总结:Database-Chapter-Four-Outline.docx

上传人:二*** 文档编号:4476557 上传时间:2024-09-24 格式:DOCX 页数:5 大小:13.59KB 下载积分:5 金币
下载 相关 举报
数据库课件总结:Database-Chapter-Four-Outline.docx_第1页
第1页 / 共5页
本文档共5页,全文阅读请下载到手机保存,查看更方便
资源描述
Database Chapter Four Outline Chapter 4: Advanced SQLSQL Data Types and Schemas EXACT(f7e/d from d) CAST e AS tcreate type Dollars as numeric (12,2) final create domain person_name char(20) not null Types and domains are similar. Domains can have constraints, such as not null, specified on them. Domains are not strongly typed. Domain Constraints Domain constraints are the most elementary form of integrity constraint. They test values inserted in the database, and test queries to ensure that the comparisons make sense. Large-Object Types Large objects (photos, videos, CAD files, etc.) are stored as a large object: blob: binary large object - object is a large collection of uninterpreted binary data (whose interpretation is left toan application outside of the database system) clob: character large object - object is a large collection of character data When a query returns a large object, a pointer is returned rather than the large object itself. Constraints on a Single Relationnot null primary keyunique check (P), where P is a predicate Candidate keys are permitted to be null unless they have explicitly been declared to be not null (in contrast to primary keys). create table depositor [customer_name char(20), account_number char(lO), primary key (customer_name, account_number), foreign key (account_number) references account, foreign key (customer_name) references customer)Assertions create assertion <assertion-name> check <predicate>Forms of authorization on parts of the database: Read - allows reading, but not modification of data. Insert - allows insertion of new data, but not modification of existing data. Update - allows modification, but not deletion of data. Delete - allows deletion of data. Authorization Specification in SQLThe grant statement is used to confer authorization grant <privilege list>on <relation name or view name> to <user list> grant select on branch to Ui with grant optionRevoking Authorization in SQL revoke select on branch from Ui, U2, U3Trigger Example in SQL:1999 ECA(Event-Condition-Action model) Create trigger o verdraft-trigger after update on accountnrow nrow referencingnewrowasfor each row when nrow.balance < 0referencing old row as : for deletes and updates referencing new row as : for inserts and updatesSQL Functions create function account_count (customer_name varchar(20))returns integer begindeclare account integer; select count (*) into accountfrom depositor where depositor.customer_name = customer_namereturn account; endcreate function accounts_of (customer_name char(20) returns table ( account_number char(lO),branch_name charflS), balance numeric(12,2)) SQL Procedurescreate procedure account count oroc (in title varchar(20), out a count integer) begin select count(author) into a count from depositor where deoositor.customer name = account count oroc. customer name end declare account integer;call account_count_proc( "Smith", account); ■ Specify the query in SQL and declare a cursor for itEXEC SQL declare ccursorforselect customer name, customer city from depositor, customer, account where depositor.customer name = customer.customer nameWVW^WVWXAA/W\AAAAAAAAAAAAAAAAAA/WWSAAAAAA/SAAAA/WW VWXAA/SAAAAAAAAAAAAAAAAAA/WSAAA/SAAA/WW'v4AAAAAAAAAAAAA/'v and depositor account number= accountaccount numberIXAAAAAAAA/VSAAAAAAAAAAAAAAAAAAA/S/V\A/\A/ W\AAAAAAAAAAAAAA/WSZvW\AAAAAAAAAAAAA>yWW\AAAAAAAAAA^ an d account.balance > :amountEND_EXEC ODBCOpen DataBase Connectivity(ODBC) standard standard for application program to communicate with a database server. application program interface (API) to► open a connection with a database, ► send queries and updates,get back results. Applications such as GUI, spreadsheets, etc. can use ODBCJDBC JDBC is a Java API for communicating with database systems supporting SQL JDBC supports a variety of features for querying and updating data, and for retrieving query results JDBC also supports metadata retrieval, such as querying about relations present in the database and the names and types of relation attributesModel for communicating with the database: Open a connectionCreate a “statement" object Execute queries using the Statement object to send queries and fetch resultsException mechanism to handle errors public static void JDBCexamDle(String dbid, String userid, String passwdjtry( Class.forName (lvH);Connection conn = DriverManager.aetConnection( ,vidbc:oracle:thin:@aura.bell-labs :2000:bankdbv\ userid, passwd): Statement stmt = conn .create S tatsm ent();... Do Actual Work .... stmt.close();connxIpseO; )catch (SQLException sale) { System.out.printlnf'SQLException : H + sale);) ■ Execute query and fetch and print resultsResultSet rset = stmt.executeQuery( "select branch_name, avg( balance) from accountgroup by branch-name,1); while (rset.next()){System .out.println( rsetgetStringCbranch-name") +11 M + rset.getFloat(2));
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服