



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATABASE SYSTEMS; Subject: COMPUTER SCIENCE; University: Texas A&M University; Term: Summer 1 2008;
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




CREATE TABLE classes ( class varchar(20) NOT NULL PRIMARY KEY, type char(2), country varchar(20), numGuns int, bore int, disp int ); CREATE TABLE battles ( name varchar(20) NOT NULL PRIMARY KEY, date varchar(20) ); CREATE TABLE outcomes ( ship varchar(20) NOT NULL, battle varchar(20) NOT NULL, result varchar(10), CONSTRAINT oc_pk PRIMARY KEY(ship, battle) ); CREATE TABLE ships ( name varchar(20), class varchar(20), launched int ); If the ships table is already created in DERBY, we could say: ij> alter table ships alter column name not null; 0 rows inserted/updated/deleted ij> alter table ships add constraint s_pk primary key(name); 0 rows inserted/updated/deleted ij>
alter table ships add constraint s_pk primary key(name); alter table outcomes add constraint o_fk foreign key(ship) references ships(name);
ij> insert into product values ('H', NULL, 'printer'); 1 row inserted/updated/deleted ij> delete from product where model is NULL; 1 row inserted/updated/deleted ij> alter table Product add constraint modnNotNull CHECK (MODEL is not NULL); 0 rows inserted/updated/deleted ij> insert into product values ('H', NULL, 'printer'); ERROR 23513: The check constraint 'MODNNOTNULL' was violated while performing an INSERT or UPDATE on table '"APP"."PRODUCT"'. ij> alter table product drop constraint modnnotnull; 0 rows inserted/updated/deleted ij> Notice the SQLState 23513 issued above
ij> alter table PC add constraint a_check CHECK(NOT(speed<1200 and price > 1500); ERROR X0Y59: Attempt to add or enable constraint(s) on table '"APP"."PC"' failed because the table contains 2 row(s) that violate the following check constraint(s): A_CHECK. ij> select * from PC; MOD&|SPEED |RAM |HD |RD |PRICE
1001|700 |64 |10 |48xCD | 1002|1500 |128 |60 |12xDVD| 1003|866 |128 |20 |8xDVD | 1004|866 |64 |10 |12xDVD| 1005|1000 |128 |20 |12xDVD| 1006|1300 |256 |40 |16xDVD| 1007|1400 |128 |80 |12xDVD| 1008|700 |64 |30 |24xCD | 1009|1200 |128 |80 |16xDVD| 1010|750 |64 |30 |40xCD | 1011|1100 |128 |60 |16xDVD| 1012|350 |64 |7 |48xCD | 1013|733 |256 |60 |12xDVD|
13 rows selected ij>
(hd<20 and price>2000)));
ij> alter table Laptop add constraint b_check CHECK(NOT(screen<15 and (hd<20 and price>2000))); ERROR X0Y59: Attempt to add or enable constraint(s) on table '"APP"."LAPTOP"' failed because the table contains 1 row(s) that violate the following check constraint(s): B_CHECK. ij> select * from laptop; MOD&|SPEED |RAM |HD |SCRE&|PRICE
2001|700 |64 |5 |12.1 | 2002|800 |96 |10 |15.1 | 2003|850 |64 |10 |15.1 | 2004|550 |32 |5 |12.1 | 2005|600 |64 |6 |12.1 | 2006|800 |96 |20 |15.7 | 2007|850 |128 |20 |15.0 | 2008|650 |64 |10 |12.1 | 2009|750 |256 |20 |15.1 | 2010|366 |64 |10 |12.1 |
10 rows selected ij>
ij> alter table classes add constraint d_check CHECK(numGuns <= 14); ERROR X0Y59: Attempt to add or enable constraint(s) on table '"APP"."CLASSES"' failed because the table contains 1 row(s) that violate the following check constraint(s): D_CHECK. ij>