print "Using database observations"
use observations
go

print "Creating table isaac_all"
go

Create table isaac_all
(
	dp_id			varchar(45) not null,
	det_chop_ncycles	smallint null,
	det_dit			float null,
	det_mindit		float null,
	det_ndit		smallint null,
	det_mode_name		varchar(30) null,
	det_win_nx		smallint null,
	det_win_ny		smallint null,
	det_win_startx		float null,
	det_win_starty		float null,
	ins_filt1_name		varchar(10) null,
	ins_filt2_name		varchar(10) null,
	ins_filt3_name		varchar(10) null,
	ins_filt4_name		varchar(10) null,
	ins_grat_name		varchar(10) null,
	ins_grat_order		smallint null,
	ins_grat_wlen		float null,
	ins_lamp1_name		varchar(10) null,
	ins_lamp1_time		float null,
	ins_lamp2_name		varchar(10) null,
	ins_lamp2_time		float null,
	ins_lamp3_name		varchar(10) null,
	ins_lamp3_time		float null,
	ins_mode		varchar(30) null,
	ins_opti1_name		varchar(10) null,
	ins_pixscale		float null,
	ins_temp_cs_mean	float null,
	ins_temp_detlw		float null,
	ins_temp_detsw		float null,
	ins_temp_dwarm1_mean	float null,
	ins_temp_dwarm2_mean	float null,
	ins_temp_sorp_mean	float null,
	ins_temp_vacp		float null,
	tpl_id			varchar(30) null,
	tpl_nexp		smallint null,
	tpl_exp_no		smallint null,
	tpl_start		varchar(24) null,
	tel_dome_status		varchar(10) null,
	tel_alt			float null,
	tel_az			float null,
	naxis			tinyint null,
	naxis3			smallint null,
	dimm_fwhm_avg		float null,
	dimm_fwhm_rms		float null,
	night_flag		tinyint null,
	moon_illu		smallint null,
	lst			float null,
	utc			float null,
)

print "Creating indices on isaac_all table"
go

create unique clustered index dp_id
	on isaac_all ( dp_id )
go

grant select on isaac_all to public
grant insert,update on isaac_all to frameingest
grant all on isaac_all to archeso
go
