Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 23 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
23
Dung lượng
221 KB
Nội dung
Brad Lloyd & Michelle Zukowski 1 Design and Implementation Design and Implementation CIS 400 Final Project CIS 400 Final Project Dr. Bruce Maxim Dr. Bruce Maxim S Q L Brad Lloyd & Michelle Zukowski 2 An Overview of An Overview of SQL SQL • SQL stands for SQL stands for S S tructured tructured Q Q uery uery L L anguage. anguage. • It is the most commonly used relational It is the most commonly used relational database language today. database language today. • SQL works with a variety of different fourth- SQL works with a variety of different fourth- generation (4GL) programming languages, generation (4GL) programming languages, such as Visual Basic. such as Visual Basic. S Q L Brad Lloyd & Michelle Zukowski 3 SQL is used for: SQL is used for: • Data Manipulation Data Manipulation • Data Definition Data Definition • Data Administration Data Administration • All are expressed as an SQL statement All are expressed as an SQL statement or command. or command. S Q L Brad Lloyd & Michelle Zukowski 4 SQL SQL Requirements Requirements • SQL Must be embedded in a programming SQL Must be embedded in a programming language, or used with a 4GL like VB language, or used with a 4GL like VB • SQL is a free form language so there is no SQL is a free form language so there is no limit to the the number of words per line or limit to the the number of words per line or fixed line break. fixed line break. • Syntax statements, words or phrases are Syntax statements, words or phrases are always in lower case; keywords are in always in lower case; keywords are in uppercase. uppercase. S Q L Not all versions are case sensitive! Not all versions are case sensitive! Brad Lloyd & Michelle Zukowski 5 SQL is a Relational Database SQL is a Relational Database • Represent all info in database as tables Represent all info in database as tables • Keep logical representation of data independent from its physical Keep logical representation of data independent from its physical storage characteristics storage characteristics • Use one high-level language for structuring, querying, and changing Use one high-level language for structuring, querying, and changing info in the database info in the database • Support the main relational operations Support the main relational operations • Support alternate ways of looking at data in tables Support alternate ways of looking at data in tables • Provide a method for differentiating between unknown values and Provide a method for differentiating between unknown values and nulls (zero or blank) nulls (zero or blank) • Support Mechanisms for integrity, authorization, transactions, and Support Mechanisms for integrity, authorization, transactions, and recovery recovery A Fully Relational Database Management System must: A Fully Relational Database Management System must: Brad Lloyd & Michelle Zukowski 6 Design Design • SQL represents all information in the SQL represents all information in the form of form of tables tables • Supports three relational operations: Supports three relational operations: selection, projection, selection, projection, and and join join . These . These are for specifying exactly what data you are for specifying exactly what data you want to display or use want to display or use • SQL is used for data manipulation, SQL is used for data manipulation, definition and administration definition and administration SQL Brad Lloyd & Michelle Zukowski 7 Rows describe the Occurrence of an Entity Table Design Table Design S Q L Name Address Jane Doe 123 Main Street John Smith 456 Second Street Mary Poe 789 Third Ave Columns describe one characteristic of the entity Brad Lloyd & Michelle Zukowski 8 Data Retrieval (Queries) Data Retrieval (Queries) • Queries search the database, fetch info, Queries search the database, fetch info, and display it. This is done using the and display it. This is done using the keyword keyword SELECT SELECT * FROM publishers SELECT * FROM publishers pub_id pub_name address state 0736 New Age Books 1 1 st Street MA 0987 Binnet & Hardley 2 2 nd Street DC 1120 Algodata Infosys 3 3 rd Street CA • The The * * Operator asks for every column in Operator asks for every column in the table. the table. Brad Lloyd & Michelle Zukowski 9 Data Retrieval (Queries) Data Retrieval (Queries) • Queries can be more specific with a few Queries can be more specific with a few more lines more lines pub_id pub_name address state 0736 New Age Books 1 1 st Street MA 0987 Binnet & Hardley 2 2 nd Street DC 1120 Algodata Infosys 3 3 rd Street CA • Only publishers in CA are displayed Only publishers in CA are displayed SELECT * SELECT * from publishers from publishers where state = ‘CA’ where state = ‘CA’ Brad Lloyd & Michelle Zukowski 10 Data Input Data Input • Putting data into a table is accomplished Putting data into a table is accomplished using the keyword using the keyword INSERT pub_id pub_name address state 0736 New Age Books 1 1 st Street MA 0987 Binnet & Hardley 2 2 nd Street DC 1120 Algodata Infosys 3 3 rd Street CA • Table is updated with new information Table is updated with new information INSERT INTO publishers INSERT INTO publishers VALUES (‘0010’, ‘pragmatics’, ‘4 4 VALUES (‘0010’, ‘pragmatics’, ‘4 4 th th Ln’, ‘chicago’, ‘il’) Ln’, ‘chicago’, ‘il’) pub_id pub_name address state 0010 Pragmatics 4 4 th Ln IL 0736 New Age Books 1 1 st Street MA 0987 Binnet & Hardley 2 2 nd Street DC 1120 Algodata Infosys 3 3 rd Street CA Keyword Variable [...]... be entered directly at the command prompt of the SQL software being used (such as mySQL) 12 Using SQL To begin, you must first CREATE a database using the following SQL statement: CREATE DATABASE database_name Depending on the version of SQL being used the following statement is needed to begin using the database: USE database_name Brad Lloyd & Michelle Zukowski 13 Using SQL • To create a table in the... Using SQL The DROP statement is also used to delete an entire database DROP DATABASE authors auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI DROP removed the database and returned the memory to system Brad Lloyd & Michelle Zukowski 21 Conclusion • SQL is a versatile language that can integrate with numerous 4GL languages and applications • SQL simplifies... database in SQL • User Tables: contain information that is the database management system • System Tables: contain the database description, kept up to date by DBMS itself Relation Table Tuple Attribute Brad Lloyd & Michelle Zukowski Row Column 11 Using SQL SQL statements can be embedded into a program (cgi or perl script, Visual Basic, MS Access) OR Brad Lloyd & Michelle Zukowski Da SQ ta L ba se SQL statements... char string) Brad Lloyd & Michelle Zukowski 14 Using SQL • To insert data in the current table, use the keyword INSERT INTO INSERT INTO authors values(‘000000001’, ‘John Smith’) • Then issue the statement SELECT * FROM authors auth_id auth_name 000000001 John Smith Brad Lloyd & Michelle Zukowski 15 Using SQL If you only want to display the author’s name and city from the following table: auth_id auth_name... and applications • SQL simplifies data manipulation by reducing the amount of code required • More reliable than creating a database using files with linked-list implementation Brad Lloyd & Michelle Zukowski 22 References • “The Practical SQL Handbook”, Third Edition, Bowman Brad Lloyd & Michelle Zukowski 23 ... Jane Doe Dearborn John Smith Taylor Brad Lloyd & Michelle Zukowski 16 Using SQL To delete data from a table, use the DELETE statement: DELETE from authors WHERE auth_name=‘John Smith’ auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI Brad Lloyd & Michelle Zukowski 17 Using SQL To Update information in a database use the UPDATE keyword UPDATE authors... Michelle Zukowski 18 Using SQL To change a table in a database use ALTER TABLE ADD adds a characteristic Initializer ALTER TABLE authors Type ADD birth_date datetime null auth_id auth_name auth_city auth_state birth_date 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI ADD puts a new column in the table called birth_date Brad Lloyd & Michelle Zukowski 19 Using SQL To delete a column or . expressed as an SQL statement or command. or command. S Q L Brad Lloyd & Michelle Zukowski 4 SQL SQL Requirements Requirements • SQL Must be embedded in a programming SQL Must be embedded. Maxim S Q L Brad Lloyd & Michelle Zukowski 2 An Overview of An Overview of SQL SQL • SQL stands for SQL stands for S S tructured tructured Q Q uery uery L L anguage. anguage. • It is. Brad Lloyd & Michelle Zukowski 1 Design and Implementation Design and Implementation CIS 400 Final Project CIS 400 Final Project Dr. Bruce Maxim Dr.