CS5483 Data Warehousing and Data Mining

Exercise 1: Database Practice: Microsoft SQL Server
Accessing MS SQL Server
1. 2. 3. 4. Login Windows XP by entering your CS LAB account and password Click Start => All Programs and select “Microsoft SQL Server” Click the “Query Analyzer” item Under “Connect to SQL Server” window, under “SQL Server:” type / select “w2ksc” from the browse button, under “Use SQL Server Authentication”, “Login name:” text box, type your group number, for example “grp##” (## is your group number, e.g. grp01), under “ Password” text box, type “abc123”, click the “OK” button to connect to the server Under the “grp##_db” Database, type different commands within the query area, then the result will be shown in “Result” area. If you want to change your password, you may type this statement in “Query” area: sp_password old_password, new_password For example sp_password 'abc123', 'new123' Click the “Play” button Reminder: • You have the sole responsibility of keeping and remembering your new password • After every execution of the statements, you should clear the previous statement(s) 7. Type then execute the following statement: create table course ( course_no integer not null, primary key(course_no) ) 8. Type then execute the statement create table person ( id_no integer not null, name varchar(50), birth_date datetime, height float, weight float, primary key(id_no) ) 9. Type then execute create table student ( id_no integer not null, student_id integer not null, dept_name varchar(100), course_taken integer, primary key(id_no) ) 10. Type then execute Page 1 of 4

5. 6.

11. weight) values (1. height. Type then execute insert into person (id_no. Type then execute alter table course add course_name varchar (50) null 13. Type then execute create table previous_course_required ( course_no integer not null. weight) values (2. primary key (course_no. birth_date. id_no). name. name. foreign key (course_no) references course(course_no). Type then execute create table pt_student ( id_no integer not null. 'Able Chitson'. Type then execute create table students_registered ( course_no integer not null.create table ft_student ( id_no integer not null. Type then execute alter table course add teacher_name varchar (50) null 15. 1. 'mar 2. foreign key (course_no) references course(course_no) ) 16.0'. grade integer. primary key (previous_course_no). 1997'. previous_course_no varchar(100) not null. primary key(id_no) ) 11. Type then execute Page 2 of 4 .22. birth_date. primary key(id_no) ) 12. foreign key (id_no) references student(id_no) ) 17.11) 18. 'John Doe'. height. 2. 2. 1. 'mar 1. id_no integer not null.22) 19. Type then execute alter table course add credit integer null 14. Type then execute insert into person (id_no. 1997 0:0:0.

Type then execute insert into ft_student (id_no. name. 3. course_taken) values (5. weight) values (5. name. 'CS101') 27. 5) 26. teacher_name) values (4. birth_date.insert into person (id_no. 'Peter Smith') 22. 0) 25. teacher_name) values (5. 'Keith Reagon'. 'Computer Science'. 5. dept_name. Type then execute insert into course (course_no. Type then execute insert into student (id_no. id_no) values (4. Type then execute insert into course (course_no. 1997'.55) 24. 3. Type then execute insert into students_registered (course_no.33. dept_name. credit. 'Chris Bloor'. birth_date. course_name. course_taken) values (3. Type then execute insert into student (id_no. 3. Type then execute Page 3 of 4 . credit. height. 5. Type then execute select * from course 31. previous_course_no) values (4. weight) values (3. 'Computer Science'. student_id. Type then execute insert into previous_course_required (course_no. 3) 29. height. id_no) values (5. 5. 3) 30. 'CS102') 28. 'Data Engineering'. 'mar 3.55. 5.33) 20. previous_course_no) values (4. course_name. 3. Type then execute insert into students_registered (course_no. Type then execute insert into person (id_no. 'mar 5. grade) values (5. student_id. 1997'. Type then execute insert into previous_course_required (course_no. 'Mike Denny') 23. 4) 21. 'Database'.

column type. Type then execute select * from ft_student 33. 29 Type then execute execute show_course 4 System Tables In schema translation design. Page 4 of 4 . Metadata of source database is extracted from system tables. default value. MS SQL Server system tables used by our schema translation are shown in following table. 28 35. “cold” is the order of the columns in a table. column length. systypes . sysobjects sysreferences Sample SQL Statements Get table information To create a tables. null value and identity. Contains one row for each each database object and temporary object. Important System Tables used in Project Tables Name syscolumns sysindexes Function Contains one row for every column in every table and view. This SQL statement is order by the “object ID” and the “Column ID” (syscolumns. Contains one row for each FOREIGN KEY constraint. and a row for each parameter in a stored procedure. The first column in a table is “1” and the second is “2” and so on. syscomments and sysobjects. Type then execute show_person Type then execute create proc show_course @incourse_no integer as select * from course where course_no = @incourse_no return 36. Type then execute create proc show_person as select * from person return 34. Additionally. Contains one row for each each clustered index and one row for each nonclustered index. These tables contains the tables name. we should look at the tables syscolumns . These indexes are the result of a CREAT INDEX statement or the CREATE TABLE statement with a PRIMARY KEY or UNIQUE constraint.select * from person 32. System tables are tables used to store information about the system (the database catalog) or an individual database (the database catalog). column name. the database schema from source database is extracted using MS SQL server's system tables. sysindexes contains one row for each table that has no clustered index and one row for each table that contains text or image columns.colid).

Sign up to vote on this title
UsefulNot useful