Learning SQL Second Edition phần 1 docx

34 274 0
Learning SQL Second Edition phần 1 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... http://examples.oreilly.com/learningsql/ and run it from the mysql utility If you saved the file as c:\temp\LearningSQLExample .sql, you would need to do the following: 1 If you have logged out of the mysql tool, repeat steps 7 and 8 from Table 2 -1 2 Type source c:\temp\LearningSQLExample .sql; and press Enter You should now have a working database populated with all the data needed for the examples in this book Using the mysql... tables Figure 1- 3 shows how George’s and Sue’s account information would appear in this context Customer Account cust_id fname lname 1 George Blake 10 3 CHK 1 $75.00 2 Sue Smith 10 4 SAV 1 $250.00 10 5 CHK 2 $783.64 10 6 MM 2 $500.00 10 7 LOC 2 0 Product account_id product_cd cust_id balance Transaction product_cd name CHK Checking txn_id txn_type_cd account_id amount 978 DBT 10 3 $10 0.00 2004- 01- 22 date SAV... amount 978 DBT 10 3 $10 0.00 2004- 01- 22 date SAV Savings 979 CDT 10 3 $25.00 2004-02-05 MM Money market 980 DBT 10 4 $250.00 2004-03-09 LOC Line of credit 9 81 DBT 10 5 $10 00.00 2004-03-25 982 CDT 10 5 $13 8.50 2004-04-02 983 CDT 10 5 $77.86 984 DBT 10 6 $500.00 2004-03-27 2004-04-04 Figure 1- 3 Relational view of account data There are four tables in Figure 1- 3 representing the four entities discussed so far: customer,... Table 1- 2 shows some of the available options for integrating SQL into a specific language What Is SQL? | 9 Download at WoweBook.Com Table 1- 2 SQL integration toolkits Language Toolkit Java JDBC (Java Database Connectivity; JavaSoft) C++ Rogue Wave SourcePro DB (third-party tool to connect to Oracle, SQL Server, MySQL, Informix, DB2, Sybase, and PostgreSQL databases) C/C++ Pro*C (Oracle), MySQL C API... database bank; 5 Create the lrngsql database user with full privileges on the bank database grant all privileges on bank.* to 'lrngsql'@'localhost' identified by 'xyz'; 6 Exit the mysql tool quit; 7 Log in to MySQL as lrngsql mysql -u lrngsql -p; 8 Attach to the bank database use bank; 16 | Chapter 2: Creating and Populating a Database Download at WoweBook.Com You now have a MySQL server, a database, and... which was, finally, renamed SQL SQL is now entering middle age (as is this author, alas), and it has undergone a great deal of change along the way In the mid -19 80s, the American National Standards Institute (ANSI) began working on the first standard for the SQL language, which was published in 19 86 Subsequent refinements led to new releases of the SQL standard in 19 89, 19 92, 19 99, 2003, and 2006 Along... database servers are PostgreSQL and MySQL The MySQL website (http://www mysql.com) currently claims over 10 million installations, its server is available for free, 12 | Chapter 1:  A Little Background Download at WoweBook.Com and I have found its server to be extremely simple to download and install For these reasons, I have decided that all examples for this book be run against a MySQL (version 6.0) database,... install a MySQL 6.0 server on a Windows computer: 1 Go to the download page for the MySQL Database Server at http://dev.mysql.com/ downloads If you are loading version 6.0, the full URL is http://dev.mysql.com/ downloads/mysql/6.0.html 2 Download the Windows Essentials (x86) package, which includes only the commonly used tools 3 When asked “Do you want to run or save this file?” click Run 4 The MySQL Server... if you want to know the current date and time, you could issue the following query: mysql> SELECT now(); + -+ | now() | + -+ | 2008-02 -19 16 :48:46 | + -+ 1 row in set (0. 01 sec) The now() function is a built-in MySQL function that returns the current date and time As you can see, the mysql command-line tool formats the results of your queries within a rectangle bounded by... Smith Customers Checking Savings Checking MoneyMkt Line of credit Accounts Debit of $10 0.00 on 2004- 01- 22 Debit of $250.00 on 2004-03-09 Debit of $10 00.00 on 2004-03-25 Credit of $25.00 on 2004-02-05 Debit of $500.00 on 2004-03-27 Credit of $13 8.50 on 2004-04-02 Credit of $77.86 on 2004-04-04 Transactions Figure 1- 1 Hierarchical view of account data George and Sue each have their own tree containing . context. 2004- 01- 22 $10 0.0 010 3DBT978 dateamountaccount_idtxn_type_cdtxn_id 2004-02-05$25.0 010 3CDT979 2004-03-09$250.0 010 4DBT980 2004-03-25 $10 00.0 010 5DBT9 81 2004-04-02 $13 8.5 010 5CDT982 2004-04-04$77.8 610 5CDT983 2004-03-27$500.0 010 6DBT984 Transaction $75.001CHK103 balancecust_idproduct_cdaccount_id $250.001SAV104 $783.642CHK105 $500.002MM106 02LOC107 Account BlakeGeorge1 lnamefnamecust_id SmithSue2 Customer CheckingCHK nameproduct_cd SavingsSAV Money. Knowledge 11 1 7. Data Generation, Conversion, and Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3 Working with String Data 11 3 String Generation 11 4 String Manipulation 11 9 Working. . . . . . . . 15 Creating a MySQL Database 15 Using the mysql Command-Line Tool 17 MySQL Data Types 18 Character Data 18 Numeric Data 21 Temporal Data 23 Table Creation 25 Step 1: Design 25 Step

Ngày đăng: 08/08/2014, 18:22

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan