﻿DROP TABLE products

CREATE TABLE products(
	product_no integer NOT NULL,
	name text,
	price numeric DEFAULT 200);

INSERT INTO products ("product_no", "name") VALUES (1,'pc')

ALTER TABLE products ADD UNIQUE (product_no) 

DELETE from products WHERE name ='pc'

INSERT INTO products ("product_no", "name") VALUES (2,'pc')


CREATE TABLE orders(
	order_id integer PRIMARY KEY,
	product_no integer REFERENCES products (product_no),
	quantity integer);



INSERT INTO orders ("order_id", "product_no", "quantity") VALUES (1,'1', '354')









CREATE SEQUENCE lakes_gid_seq;

--Apply sequence rules in create table:
ALTER TABLE products  ALTER product_no SET DEFAULT nextval('tablename_colname_seq');


INSERT INTO products ("name") VALUES ('Ulan')


SELECT nextval('tablename_colname_seq')

ALTER SEQUENCE tablename_colname_seq RESTART 27;





ALTER TABLE "Lakes" ALTER the_geom SET NOT NULL



ALTER TABLE "Lakes" ADD CHECK (the_geom IS NOT NULL) 







--Change sequence ownership to table, so that if delected then sequence is also deleted
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
INSERT INTO tablename(name1) values ('Centuki'), ('derbi'), ('pastoral');
DROP TABLE tablename;
-- //get the next value in sequence (nextval...):
Select currval('tablename_colname_seq');