sgbd1 sgbd2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Create table test1(ID int , nem int , primary key (ID,nem))

Create table test2(ID int , nem int foreign key references test1(nem))

Create table test3(ID int , nem int check (nem in (1,2)))

Create table test4(ID int , nem int unique)

Create table test5(ID int constraint c1 primary key , nem int)

SELECT nom FROM tarik WHERE condition AND|OR condition

ALTER TABLE tarik ADD nom varchar(20)

ALTER TABLE tarik DROP COLUMN nom varchar(20)

SELECT column_name AS column_alias FROM table_name

SELECT nom FROM tarik WHERE CIN BETWEEN 125 AND 154

CREATE INDEX index1 ON tarik (nom)

CREATE VIEW view1 AS SELECT nom FROM tarik WHERE condition

DELETE * FROM tarik WHERE

DROP DATABASE database_tarik

DROP INDEX tarik.index1

DROP TABLE tarik

SELECT nom FROM tarik WHERE nom =ouahmani GROUP BY nom

SELECT nom FROM tarik WHERE nom IN (ouahmani,achibat,badri…..)

INSERT INTO tarik VALUES (‘tarik’, ‘ouahmani’,’ ic154525’,20)

SELECT nom FROM tarik INNER JOIN chadia  ON tarik .nom= chadia .nom

SELECT nom FROM tarik WHERE tarik LIKE pattern

SELECT nom FROM tarik ORDER BY nom [ASC|DESC]

SELECT nom FROM tarik

SELECT DISTINCT nom FROM tarik

SELECT TOP 3 nom FROM table_name

TRUNCATE TABLE tarik

SELECT nom FROM tarik UNION SELECT nom FROM chadia


UPDATE tarik SET nom=ouahmani , prenom=chadia

ALTER TABLE tarik ADD CONSTRAINT c1 CHECK (ID > 0 AND nom='ouahmani')

ALTER TABLE tarik Drop CONSTRAINT c1

ALTER TABLE tarik ALTER nom SET DEFAULT 'ouahmani'

SELECT nom,nem FROM tarik WHERE nem IS NULL

SELECT AVG(nem) FROM tarik;

SELECT COUNT(*)FROM tarik;

SELECT FIRST(nom) FROM tarik;

SELECT LASTE(nom) FROM tarik;

SELECT MAX(nom) FROM tarik;

SELECT SUM(nem) FROM tarik;

SELECT MID(nom,1,4)FROM tarik;

SELECT LEN(nom) FROM tarik;

SELECT NOW() FROM tarik;

Having + en delete cascade + on-set-value @++

LIKE 's%' Les constraint est : NOT DATE est


LIKE '%s' NULL + UNIQUE + CONVERT()
LIKE'%land%' PRIMARY KEY +
NOT LIKE '%land%'
,DATEDIFF()
FOREIGN KEY+ CHECK + ,DATEADD()
LIKE '_erlin' DEFAULT 
LIKE 'L_n_on' ,GETDATE()
LIKE '[bsp]%'
LIKE '[a-c]%'
LIKE '[!bsp]%'
 create database TEST

 declare @a int

print ' a = '+ cast(@a as varchar)

 declare @tarik table(nom varchar(10) primary key, nem int)

 select * from @somme

 begin
declare @x int
declare @a int
select @x = 525
select @a = 154 + @x
select @a as 'variable '
end

 declare @a int declare @b int


select @a = 1
select @b = 520
eth1:
select @a = @a+1
select @b = @a+@b
if(@a < 530 ) goto eth1
select @b ' b '

 declare cur cursor for select * from pilote


open cur
declare @id_pilote int , @nom_pilote varchar(12),
fetch next from cur into @id_pilote,@nom_pilote
while(@@FETCH_STATUS=0)
begin
print 'id_pilote :'+cast(@id_pilote as varchar(20))
+ ' nom_p ilote:'+@nom_pilote
fetch next from cur into @id_pilote,@nom_pilote
end close cur
deallocate cur

procedure + function +Transaction + Triggers @++

 create proc no_parametre


as
if exists(select * from client) -- exists = les client est trouve
select * from client
else
print 'table est vide'

exec no_parametre
 create proc parametre(@nom varchar(20),@prenom varchar(20))
as
if(select * from client where nom = @nom and prenom = @prenom)
select * from client where nom = @nom and prenom = @prenom
else
print'client ne trouve pas'
exec parametre 'ouahmani','tarik' -- afficher les informations de client qui s'appele tarik
ouahmani

 create proc renvoi_valeur (@id int ,@nom varchar(20) output,@prenom


varchar(20) output)
as
select @nom = (select nom from client where Id = @id )
select @prenom = select prenom from client where Id = @id
declare @nom varchar(20),@prenom varchar(20)
exec renvoi_valeur 1,@nom output,@prenom output -- afficher les informations de client
qu'est le ID : 1
print @nom +''+@prenom

 create proc cur_proc as


declare cur cursor for select client.nem_client , client.prenom from client join societe on
societe.nem = client.nem_client
declare @id int , @nom varchar(20) , @prenom varchar(20)/*--les variable qui se trouve
*/,@nv
fetch next from cur into @id,@nom,@prenom
set @nv = @id
print 'le ID est '+ @id
while (@@FETCH_STATUS =0)
begin
set @nv = @id
print 'le Id est : '+@id,'le NOM est : ' +@nom,'le prenom est : ' +@prenom
fetch next from cur into @id,@nom,@prenom
if(@nv <> @id)-- ID NE TROUVE
print 'le ID est ' + @id
end
close cur
deallocate cur

You might also like