Download presentation
Presentation is loading. Please wait.
Published byIbrahim Padgitt Modified over 10 years ago
1
1 I Esempio di constraints
2
2 DROP TABLE regions; CREATE TABLE regions ( region_id NUMBER CONSTRAINT region_id_nn NOT NULL, region_name VARCHAR2(25) ); CREATE UNIQUE INDEX reg_id_pk ON regions (region_id); ALTER TABLE regions ADD ( CONSTRAINT reg_id_pk PRIMARY KEY (region_id) ) ;
3
3 INSERT INTO regions VALUES ( 1, 'Piemonte'); INSERT INTO regions VALUES ( 2, 'Liguria'); select * from regions;
4
4 DROP TABLE countries; CREATE TABLE countries ( country_id CHAR(2) CONSTRAINT country_id_nn NOT NULL, country_name VARCHAR2(40), region_id NUMBER, CONSTRAINT country_c_id_pk PRIMARY KEY (country_id) ) ORGANIZATION INDEX; ALTER TABLE countries ADD ( CONSTRAINT countr_reg_fk FOREIGN KEY (region_id) REFERENCES regions(region_id) ) ;
5
5 INSERT INTO countries VALUES ( 1, 'Italia', 1); INSERT INTO countries VALUES ( 2, 'France', 2); select * from countries;
6
6 DROP TABLE locations; CREATE TABLE locations ( location_id NUMBER(4), street_address VARCHAR2(40), postal_code VARCHAR2(12), city VARCHAR2(30) CONSTRAINT loc_city_nn NOT NULL, state_province VARCHAR2(25), country_id CHAR(2) ) ; CREATE UNIQUE INDEX loc_id_pk ON locations (location_id) ; ALTER TABLE locations ADD ( CONSTRAINT loc_id_pk PRIMARY KEY (location_id), CONSTRAINT loc_c_id_fk FOREIGN KEY (country_id) REFERENCES countries(country_id) ) ;
7
7 INSERT INTO locations VALUES ( 1, 'via Botti 2','10139', 'Torino', 'TO', 1); INSERT INTO locations VALUES ( 2, 'via Crea 22','10142', 'Genova', 'GE', 1); select * from locations;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.