Vous êtes sur la page 1sur 6

1.

Create table Customer_Dept


(
Customer_Dept integer not null constraint p_K primary key,
Customer_Dept_Name varchar(10) not null
)
2.
create table Customer
(
customer_id integer not null constraint p_k primary key,
customer_name varchar(10) not null,
customer_expense integer constraint ch_k check(customer_expense<10000),
customer_phone_num integer not null constraint u_k unique,
customer_dept_id integer
)
3.
insert into customer_dept values(100,'product')
insert into customer_dept values(200,'hr')
insert into customer_dept values(300,'sales')
sel * from customer_dept
insert into customer values(1,'Ryan',350,'345678',100)
insert into customer values(2,'Kell',386,286473,200)
insert into customer values(3,'sher',782,'928759',100)
insert into customer (customer_id, customer_name, customer_phone_num, customer_d
ept_id) values(4,'hyar','289384',100)
insert into customer values(5,'whyb',345,'89347',300)
insert into customer values(6,'vale',675,'438769',200)
sel * from customer
4.
alter table customer add location varchar(10)
alter table customer add gender char(1)
alter table customer_dept add location varchar(10)
alter table customer_dept add gender char(1)
5.
alter table customer drop column location
alter table customer drop column gender
alter table customer_dept drop column location
alter table customer_dept drop column gender
6.
alter table customer modify constraint ch_k check(customer_expense>20000)
--Error : A constraintn violation was found caused by the new check
7.
alter table customer modify constraint ch_k check(customer_expense<200)
--Error : A constraintn violation was found caused by the new check
8.

insert into customer (customer_dept_id) values(400)


---Error: It is not possible to insert as the customer id is a primary key , pri
mry key rule say s it can not be "not null"
--apart from that there are other constraints too
insert into customer (customer_id,customer_name, customer_phone_num, customer_de
pt_id) values (7,'macy',989898,400)
9.
insert into customer(customer_id) values(1)
---Error : due to constraints such as primary, not null, unique etc
10.
insert into customer (customer_id,customer_dept_id) values(8,100)
--error : due to constraintn it can not be insert as null values
11.
alter table customer rename customer_phone_num to customer_phone_number
--Error: due constraint cannot be rename
12.
alter table customer rename customer_id to customer_id1
--Error: due constraint cannot be rename
13.
alter table customer add customer_phone_number not null constraint u_p unique
--Error: no other table option can be specified when constraint is specified in
the statment
14.
alter table customer drop column customer_dept_id
sel * from customer
15.
--approach I
--step:1
show table customer
--step:2
CREATE SET TABLE SAMPLES.customer_1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
customer_id INTEGER NOT NULL,
customer_name VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL
)UNIQUE PRIMARY INDEX p_k ( customer_id )
;
--step:3
insert into customer_1
sel customer_id, customer_name from customer

--Approach II
Create table customerr_1
as (sel customer_id, customer_name from customer) with data
SHOW TABLE CUSTOMER
16.
SHOW TABLE CUSTOMER
CREATE SET TABLE SAMPLES.CUSTOMER_2 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
customer_id INTEGER NOT NULL,
customer_name VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
customer_expense INTEGER,
customer_phone_num INTEGER NOT NULL,
CONSTRAINT ch_k CHECK ( customer_expense < 10000 ))
UNIQUE PRIMARY INDEX p_k ( customer_id )
UNIQUE INDEX u_k ( customer_phone_num );
INSERT INTO CUSTOMER (CUSTOMER_DEPT_ID) VALUES(200)
--WE DROP THE CUSTOMER_DEPT_ID COLUMN SO CANNOT INSERT VALUE FOR THIS PARTICULA
R COLUMN
---Constraint voilation also.
17.
--WE DROP THE CUSTOMER_DEPT_ID COLUMN SO CANNOT INSERT VALUE FOR THIS PARTICULA
R COLUMN
SEL * FROM CUSTOMER
INSERT INTO CUSTOMER (CUSTOMER_NAME, CUSTOMER_ID,CUSTOMER_PHONE_NUM)
VALUES('JOHN',8,999999)
ALTER TABLE CUSTOMER ADD CUSTOMER_DEPT_ID INT
---AFTER ADD CUSTOMER_DEPT_ID
INSERT INTO CUSTOMER (CUSTOMER_NAME, CUSTOMER_ID,CUSTOMER_PHONE_NUM, CUSTOMER_DE
PT_ID)
VALUES('JOHNY',9,999977,001)
18.
Approach I
show table customer
CREATE SET TABLE SAMPLES.customer_3 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
customer_id INTEGER NOT NULL,
customer_name VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
customer_expense INTEGER,
customer_phone_num INTEGER NOT NULL,
CUSTOMER_DEPT_ID INTEGER,

CONSTRAINT ch_k CHECK ( customer_expense < 10000 ))


UNIQUE PRIMARY INDEX p_k ( customer_id )
UNIQUE INDEX u_k ( customer_phone_num );
insert into customer_3
sel * from customer
sel * from customer_3
Approach II
create table customerr_3 as (sel * from customer) with data

19.
delete from customer where customer_dept_id=100
20.
delete from customer where customer_dept_id=100
sel * from dbc.tables where tablename ='customer_3'
21.
Approach I
create table customerr_3 as (sel * from customer) with data
Approach II
show table customer_3
22.
delete from customer_3
23.
1.There is no data in customer_2, that because created table but did no insert d
atat into it.
2. First need to insert data into it then we can perfor update operation
like:
update customer_2 set customer_name where customer_id=2
24.
update customer set customer_expense=0 where customer_id=1
update customer set customer_expense=0 where customer_id=2
update customer set customer_expense=0 where customer_id=3
update customer set customer_expense=0 where customer_id=4
update customer set customer_expense=0 where customer_id=5
update customer set customer_expense=0 where customer_id=6
25.

sel * from customer


order by customer_id asc
sel * from customer
order by customer_id
--IF WE DID NOT MENSION ASCENDING BY DEFAULT IT DISPLYA ASCENDING ORDER
26.
sel * from customer
order by customer_DEPT_id DEsc
27.
SEL DISTINCT CUSTOMER_DEPT_ID FROM CUSTOMER
28.
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID=100
29.
SEL * FROM CUSTOMER
WHERE CUSTOMER_EXPENSE>300
30.
SEL * FROM CUSTOMER
WHERE CUSTOMER_ID BETWEEN 2 AND 5
SEL * FROM CUSTOMER
WHERE CUSTOMER_ID >=2 AND CUSTOMER_ID<=5
31.
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID =100 AND
CUSTOMER_DEPT_ID=200
----WILL SHOW '0' RECORD AS BOTH THE CONDTION SHOULD SATISFY (IS IT TRUE?)
---BIT CONFUSION WHO TO UNDERSTAND WHERE 2 CONDTION SATISFY OR ONE CONDITION
HERE IT WAS GIVE AS 'AND' SO ASSUME AS IT NEED TO SATISFY BOTH CONDITION.
32.
--using not in operator
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID NOT IN(100,200)
----using not operator
SEL * FROM CUSTOMER

WHERE NOT CUSTOMER_DEPT_ID =100 AND NOT


CUSTOMER_DEPT_ID=200
--- withh outu using not operator symbol
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID<>100 and CUSTOMER_DEPT_ID<>200

33.
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID =100
AND
CUSTOMER_EXPENSE>300
34.
SEL * FROM CUSTOMER
WHERE CUSTOMER_DEPT_ID =200
AND
CUSTOMER_EXPENSE<700
35.
SEL * FROM CUSTOMER
WHERE CUSTOMER_EXPENSE IS NULL
36.
SEL * FROM CUSTOMER
WHERE CUSTOMER_EXPENSE IS NOT NULL
37.
SEL * FROM CUSTOMER
WHERE CUSTOMER_NAME LIKE 'R%'
38.
SEL * FROM CUSTOMER
WHERE CUSTOMER_NAME LIKE '%R%'
39.
SEL * FROM CUSTOMER
WHERE CUSTOMER_NAME LIKE '%Y_'
40.
SEL * FROM CUSTOMER
WHERE CUSTOMER_NAME LIKE '__AR%'

Vous aimerez peut-être aussi