Skip to content

Instantly share code, notes, and snippets.

@WoodProgrammer
Forked from UtkucanBykl/Tablolar.md
Created June 16, 2017 09:01
Show Gist options
  • Save WoodProgrammer/d33debce29224ab40a4633087d69e208 to your computer and use it in GitHub Desktop.
Save WoodProgrammer/d33debce29224ab40a4633087d69e208 to your computer and use it in GitHub Desktop.

User Tablosu

create table users(
id serial not null primary key,
username varchar(15) not null UNIQUE,
password text not null,
email text not null UNIQUE,
c_date timestamp default current_timestamp,full_name varchar(40) , 
status boolean not null default true,balance real not null default 0,
lastlogin timestamp not null default current_timestamp,
admin boolean not null default false
);


Game Tablosu

create table game(
id serial not null primary key,
name varchar(100) notnull UNIQUE,
price real not null CHECK (price > 0),
popularity int not null,
created_date timestamp not null default current_timestamp,
update_date timestamp not null default current_timestamp,
logo varchar(200),
genre_id int not null references genre(id));

Sale Tablosu

create table sale(
id serial not null primary key,
user_id int not null references users(id),
game_id int not null references game(id),
c_date timestamp default current_timestamp,
amount real not null CHECK (price > 0));

Genre Tablosu

create table genre(
id serial not null primary key,
name varchar(40) not null UNIQUE);

Insert İşlemleri

insert into game (name,price,popularity,genre_id) values ('Wow',100,1,1);
insert into game (name,price,popularity,genre_id) values ('Metin2',300,10,2);

OrderBy Kullanımı

Büyükten küçüğe
select * from game order by created_date desc;
Küçükten büyüğe
select * from game order by created_date asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment