Lab 02 Company Database Lab 02 Company Database Create Database Company CREATE DATABASE Company ON PRIMARY ( NAME = 'Company', FILENAME = 'C:\DATA\Company.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = 'Company_log', FILENAME = 'C:\DATA\Company_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048KB , FILEGROWTH = 10%) Note: Save to file Company_DB.sql Create tables – Priamry Key – Foreign Key Lab 02 Company Database • • • • • Table Structure: Employee Field Name FName MInit LName SSN BDate Address Sex Salary SuperSSN DNo Data Type varchar(15) varchar(1) varchar(15) char(9) datetime varchar(30) char(1) numeric(10, 2) char(9) numeric(4, 0) Null NOT NULL NULL NOT NULL NOT NULL NULL NULL NULL NULL NULL NULL Department Field Name DName DNumber Mgrssn MgrStartdate Data Type varchar(15) numeric(4, 0) char(9) datetime Null NOT NULL NOT NULL NULL NULL Department Location Field Name Data Type DNumber numeric(4, 0) DLocation varchar(15) Null NOT NULL NOT NULL Project Field Name PName PNumber PLocation DNum Data Type varchar(15) numeric(4, 0) varchar(15) numeric(4, 0) Null NOT NULL NOT NULL NULL NOT NULL Works on Field Name ESSN PNo Hours Data Type char(9) numeric(4, 0) numeric(4, 1) Null NOT NULL NOT NULL NULL • Dependent Field Name Data Type ESSN char(9) Dependent_Name varchar(15) Sex char(1) BDate datetime Relationship varchar(8) Note: Save to file Company_Tab.sql Null NOT NULL NOT NULL NULL NULL NULL Lab 02 Company Database 3 Insert Data In tables Employee and Department: when entering data into table, the data is entered first and other is enterd next After they can update • Employee FName Minit LName SSN BDate Address Sex Salary Supper_SSN John B Smith 123456789 01/09/1955 Houston, M 30000 333445555 TX Franklin T Wong 333445555 12/08/1945 Houston, M 40000 888665555 TX Joyce A English 453453453 07/31/1962 Houston, F 25000 333445555 TX Ramesh K Narayan 666884444 09/15/1952 Humble, M 38000 333445555 TX James E Borg 888665555 11/10/1927 Houston, M 55000 NULL TX Jennifer S Wallace 987654321 06/20/1931 Bellaire, F 43000 888665555 TX Ahmad V Jabbar 987987987 03/29/1959 Houston, M 25000 987654321 TX Alicia J Zelaya 999887777 07/19/1958 Spring, F 25000 987654321 TX • Department DName DNumber Headquarters Administration Research Mgrssn 888665555 987654321 333445555 MgrStartdate 06/19/1971 01/01/1985 05/22/1978 • Department Location DNumber DLocation Houston Stafford Bellaire Houston Sugarland • Project PName ProductX ProductY ProductZ Computerization Reorganization Newbenefits PNumber 10 20 30 PLocation Bellaire Sugarland Houston Stafford Houston Stafford DNum 5 4 DNo 5 5 4 Lab 02 Company Database • Works on ESSN PNo 123456789 123456789 333445555 333445555 333445555 333445555 453453453 453453453 666884444 888665555 987654321 987654321 987987987 987987987 999887777 999887777 2 10 20 20 20 30 10 30 10 30 Hours 32.5 7.5 10.0 10.0 10.0 10.0 20.0 20.0 40.0 NULL 15.0 20.0 35.0 5.0 10.0 30.0 • Dependent ESSN Dependent_Name 123456789 Alice 123456789 Elizabeth 123456789 Michael 333445555 Alice 333445555 Joy 333445555 Theodore 987654321 Abner Sex F F M F F M M BDate 12/31/1978 05/05/1957 01/01/1978 04/05/1976 05/03/1948 10/25/1973 02/29/1932 Note: Save to file Company_Data.sql Relationship Daughter Spouse Son Daughter Spouse Son Spouse ... Stafford DNum 5 4 DNo 5 5 4 Lab 02 Company Database • Works on ESSN PNo 123 456 789 123 456 789 3334 455 55 3334 455 55 3334 455 55 3334 455 55 453 453 453 453 453 453 666884444 8886 655 55 987 654 321 987 654 321 987987987... Smith 123 456 789 01/09/1 955 Houston, M 30000 3334 455 55 TX Franklin T Wong 3334 455 55 12/08/19 45 Houston, M 40000 8886 655 55 TX Joyce A English 453 453 453 07/31/1962 Houston, F 250 00 3334 455 55 TX Ramesh... Narayan 666884444 09/ 15/ 1 952 Humble, M 38000 3334 455 55 TX James E Borg 8886 655 55 11/10/1927 Houston, M 55 000 NULL TX Jennifer S Wallace 987 654 321 06/20/1931 Bellaire, F 43000 8886 655 55 TX Ahmad V Jabbar