Beginning SQL
Beginning SQL Beginning SQL
Chapter 4 148 UPDATE Films SET FilmId = 13 WHERE FilmId = 12 AND FilmName = ‘The Good, the Bad, and the Facially Challenged’; UPDATE Films SET FilmId = 14 WHERE FilmId = 2 AND FilmName = ‘15th Late Afternoon’; UPDATE Films SET FilmId = 15 WHERE FilmId = 2 AND FilmName = ‘Soylent Yellow’; Execute the following SQL to create the PRIMARY KEY constraint: ALTER TABLE Films ADD CONSTRAINT films_pk PRIMARY KEY (FilmId); Next, add a PRIMARY KEY constraint to the Category table. The steps are identical to those described previously. First, add a NOT NULL constraint. If you’re using MS Access or SQL Server, the code is as follows: ALTER TABLE Category ALTER COLUMN CategoryId int NOT NULL; If you’re using MySQL or Oracle, use the following statement: ALTER TABLE Category MODIFY CategoryId int NOT NULL; Once again, with IBM’s DB2, you need to re-create the table: CREATE TABLE TempCategory ( CategoryId integer, Category varchar(100) ); INSERT INTO TempCategory SELECT * FROM Category; DROP TABLE Category; CREATE TABLE Category ( CategoryId integer NOT NULL, Category varchar(100) ); INSERT INTO Category SELECT * FROM TempCategory; DROP TABLE TempCategory;
- Page 284: Chapter 4 122 The Street, City, and
- Page 288: Chapter 4 MySQL versions prior to 5
- Page 292: Chapter 4 126 Except for IBM’s DB
- Page 296: Chapter 4 128 You can add more than
- Page 300: Chapter 4 Try It Out Adding a CHECK
- Page 304: Chapter 4 Obviously, if the table i
- Page 308: Chapter 4 134 Drop the MoreHolidayB
- Page 312: Chapter 4 136 If you want to return
- Page 316: Chapter 4 If you’re using IBM DB2
- Page 320: Chapter 4 140 index helps speed up
- Page 324: Chapter 4 142 The results you get m
- Page 328: Chapter 4 144 The results of the qu
- Page 332: Chapter 4 146 Remember, IBM DB2 doe
- Page 338: Then add the PRIMARY KEY constraint
- Page 342: ( ); FilmId integer NOT NULL, FilmN
- Page 346: ALTER TABLE Attendance ADD CONSTRAI
- Page 350: ❑ You learned the importance of e
- Page 356: Chapter 5 158 Function Operator Mul
- Page 360: Chapter 5 Consider the following SQ
- Page 364: Chapter 5 The SQRT() Function The S
- Page 368: Chapter 5 164 chairperson now also
- Page 372: Chapter 5 The FLOOR() Function The
- Page 376: Chapter 5 DVDPrice ROUND(DVDPrice,1
- Page 380: Chapter 5 Note that, as with all th
- Page 384: Chapter 5 The TRIM() Functions Trim
Chapter 4<br />
148<br />
UPDATE Films<br />
SET FilmId = 13<br />
WHERE FilmId = 12 AND<br />
FilmName = ‘The Good, the Bad, and the Facially Challenged’;<br />
UPDATE Films<br />
SET FilmId = 14<br />
WHERE FilmId = 2 AND<br />
FilmName = ‘15th Late Afternoon’;<br />
UPDATE Films<br />
SET FilmId = 15<br />
WHERE FilmId = 2 AND<br />
FilmName = ‘Soylent Yellow’;<br />
Execute the following <strong>SQL</strong> to create the PRIMARY KEY constraint:<br />
ALTER TABLE Films<br />
ADD CONSTRAINT films_pk PRIMARY KEY (FilmId);<br />
Next, add a PRIMARY KEY constraint to the Category table. The steps are identical to those described<br />
previously. First, add a NOT NULL constraint. If you’re using MS Access or <strong>SQL</strong> Server, the code is as<br />
follows:<br />
ALTER TABLE Category<br />
ALTER COLUMN CategoryId int NOT NULL;<br />
If you’re using My<strong>SQL</strong> or Oracle, use the following statement:<br />
ALTER TABLE Category<br />
MODIFY CategoryId int NOT NULL;<br />
Once again, with IBM’s DB2, you need to re-create the table:<br />
CREATE TABLE TempCategory<br />
(<br />
CategoryId integer,<br />
Category varchar(100)<br />
);<br />
INSERT INTO TempCategory<br />
SELECT * FROM Category;<br />
DROP TABLE Category;<br />
CREATE TABLE Category<br />
(<br />
CategoryId integer NOT NULL,<br />
Category varchar(100)<br />
);<br />
INSERT INTO Category<br />
SELECT * FROM TempCategory;<br />
DROP TABLE TempCategory;