Easy PHP Websites with the Zend Framework (phần 3)

Tham khảo sách 'easy php websites with the zend framework (phần 3)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 4 INTRODUCING MYSQL 81 Because signed integer values are the default there s no need to explicitly define integers as such. Incidentally identifying an integer-related column as unsigned will result in a shift of its range to be entirely positive. For instance a signed TINYINT has a range of -128 to 127 whereas an unsigned TINYINT has a range of 0 to 255. Assigning Default Values Suppose you might not necessarily wish to rate a game at the time it s added to your collection. After all it s entirely likely you will eventually purchase a game but not be able to immediately spend adequate time playing it and so feel uncomfortable assigning a rating at the time it s inserted into the database. However you don t just want to assign a value in the range of 1-10 because it could mislead your friends into thinking you ve already rated the game. Therefore you could assign the column a default value of 0 CREATE TABLE games title VARCHAR NOT NULL release_date DATE NOT NULL price DECIMAL 4 2 NOT NULL rating TINYINT UNSIGNED NOT NULL DEFAULT 0 Creating Primary Keys As you learned earlier in this chapter a successful relational database implementation is dependent upon the ability for table rows to reference each other using some unique value. This value which uniquely identifies each row is known as a primary key and it absolutely must be unique for each and every row no matter how large the table grows. As an example if you re building a product catalog using of the Amazon Associates Web Service discussed in Chapter 10 you might consider using the unique codes uses to identify every product known as the ASIN Amazon Standard Identification Number CREATE TABLE games asin CHAR 10 NOT NULL PRIMARY KEY title VARCHAR NOT NULL release_date DATE NOT NULL price DECIMAL 4 2 NOT NULL rating TINYINT UNSIGNED NOT NULL DEFAULT 0 However there s actually a much easier way to create primary keys the automatically incrementing integer. If when adding a new row you increment

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.