Question

Created the database and all the tables in phpMyadmin. In addition, write all the sql statements...

Created the database and all the tables in phpMyadmin. In addition, write all the sql statements used in perforing the tasks in a word document and submit that for grading.

Lab 1: CREATE STATEMENT

This statement is used to create a database or a table.

  1. CREATE DATABASE

This statement is used to create a database

Syntax:

CREATE DATABASE database_name; OR

CREATE SCHEMA database_name;

Example:

CREATE DATABASE Nyumbani; OR

CREATE SCHEMA Nyumbani ;

  1. CREATE TABLE

This SQL statement is used to create a table in a relational database.

Syntax:

CREATE TABLE table_name ( Column 1 datatype [PRIMARY KEY], Column 2 datatype [NOT NULL],

:

Column n datatype

);

create table branch(

branch_no int not null primary key, br_street varchar(25) not null, br_area varchar(20),

br_town varchar(20) not null, br_pcode int not null, br_telno varchar(12)

);

Practical 1

Create the following tables using the described properties below;

  1. staff

Column name

Data type

Size

Properties

Nullity

staff_no

INT

-

PRIMARY KEY

NO

branch_no

INT

-

FOREIGN KEY (References branch(branch_no)

NO

staff_surname

VARCHAR

20

-

YES

staff_othernames

VARCHAR

30

-

NO

staff_street

VARCHAR

25

-

NO

staff_town

VARCHAR

20

-

NO

staff_pcode

INT

-

-

NO

staff_telno

VARCHAR

12

YES

staff_gender

VARCHAR

1

NO

staff_salary

DOUBLE

-

-

NO

create table staff

(staff_no int primary key,

branch_no int references branch(branch_no), staff_surname varchar(20),

staff_forenames varchar(30) not null , staff_street varchar(25) not null, staff_town varchar(20) not null, staff_pcode int not null,

staff_telno varchar(12), staff_gender varchar(1) not null, staff_salary money

);

  1. owner

Column name

Data type

Size

Properties

Nullity

owner_no

INT

-

PRIMARY KEY

NO

ow_surname

VARCHAR

20

-

NO

ow_forenames

VARCHAR

30

-

YES

ow_town

VARCHAR

20

-

NO

ow_pcode

INT

-

-

NO

  1. property_type

Column name

Data type

Size

Properties

Nullity

prop_type

INT

-

PRIMARY KEY

NO

prop_type_description

VARCHAR

20

-

NO

Homework Answers

Answer #1

CREATE TABLE `staff` (
`staff_no` int NOT NULL AUTO_INCREMENT,
`branch_no` int NOT NULL,
`staff_surname` varchar(20) DEFAULT NULL,
`staff_othernames` varchar(30) NOT NULL,
`staff_street` varchar(25) NOT NULL,
`staff_town` varchar(20) NOT NULL,
`staff_pcode` int NOT NULL,
`staff_telno` varchar(12) DEFAULT NULL,
`staff_gender` varchar(1) NOT NULL,
`staff_salary` double DEFAULT NULL,
  
PRIMARY KEY (`staff_no`),
FOREIGN KEY (branch_no) REFERENCES branch(branch_no)
)


CREATE TABLE `owner` (
`owner_no` int NOT NULL AUTO_INCREMENT,
`ow_surname` varchar(20) NOT NULL,
`ow_forenames` varchar(30),
`ow_town` varchar(20) NOT NULL,
`ow_pcode` int NOT NULL,
  
PRIMARY KEY (`owner_no`)
)

CREATE TABLE `property_type` (
`prop_type` int NOT NULL AUTO_INCREMENT,
`prop_type_description` varchar(20) NOT NULL,
  
PRIMARY KEY (`prop_type`)
)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
1. For the Pet Database described in the previous practical, write an SQL statement with a...
1. For the Pet Database described in the previous practical, write an SQL statement with a subquery to list all the people in the Owner table who own more than one pet. should be a collum of the total number of pets owned, owner id, first name and last name -- DROP TABLE PetAndOwner, Pet, PetType, Owner; CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20),...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a small number of records. However, the data contained within it is expected to grow significantly in the future. Creating indexes on commonly searched columns is a way performance issues can be minimized. Write a command to create an index on student_name column of the student table. Create view – 1 mark Write a command to create a view to list the student ID and...
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address...
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address VARCHAR(50) NOT NULL, City TEXT NULL, State CHAR(2) NULL, ZipCode INT(11) NOT NULL, OfficeNum VARCHAR(15) NOT NULL, FaxNum VARCHAR(15) NOT NULL); CREATE TABLE Employee(EmployeeIDNumber VARCHAR(15) NOT NULL,FirstName VARCHAR(35) NOT NULL, LastName VARCHAR(35) NOT NULL, Email VARCHAR(100) NOT NULL, BranchIDNumber VARCHAR(11) NOT NULL, FOREIGN KEY(BranchIDNumber) REFERENCES Branch(BranchIDNumber), JobTitle ENUM("Manager","Staff") NOT NULL, Salary DECIMAL(8, 2) NOT NULL, HomeNumber VARCHAR(13) NULL, CellNumber VARCHAR(13) NOT NULL); CREATE TABLE...
Write the SQL statements for creating a table Event with primary key e_id, and an event...
Write the SQL statements for creating a table Event with primary key e_id, and an event date, e_date that cannot be null. Also write the statements to create a table Participant with primary key p_id, a name that can be up to 30 characters long but may be shorter, and an event e_id as a foreign key that references the corresponding event.
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE TABLE Student (  sid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  address VARCHAR(20) NOT NULL,  major CHAR(2)); CREATE TABLE Professor (  pid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  department VARCHAR(10) NOT NULL); CREATE TABLE Course (  cid INT PRIMARY KEY,  title VARCHAR(20) NOT NULL UNIQUE,  credits INT NOT NULL,  area VARCHAR(5) NOT NULL); CREATE TABLE Transcript (  sid INT,  cid INT,  pid INT,  semester VARCHAR(9),  year YEAR,  grade CHAR(1) NOT NULL,  PRIMARY KEY (sid, cid, semester, year),  FOREIGN KEY (sid) REFERENCES Student...
If you had to create a new table in your database called EMPLOYEE and load data...
If you had to create a new table in your database called EMPLOYEE and load data into it using SQL commands below. CREATE TABLE EMPLOYEE (               EMP_ID INT PRIMARY KEY,               EMP_FNAME VARCHAR(200) NOT NULL,               EMP_LNAME VARCHAR(200) NOT NULL,               EMP_CITY VARCHAR(500) NULL ,               EMP_STATE VARCHAR(20) NULL ) INSERT INTO EMPLOYEE VALUE (1, ‘Kevin’, ‘Lailnay’, NULL, ‘PA’) INSERT INTO EMPLOYEE VALUE (2, ‘Sarita, ‘Kawn, ‘Princeton’,’NJ’) INSERT INTO EMPLOYEE VALUE (2, ‘Gloria, ‘Pitts, ‘Allentown, ‘PA’) INSERT INTO EMPLOYEE...
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
Write a script to create the following tables with attributes as specified(SQL) Customer table with Customer’s...
Write a script to create the following tables with attributes as specified(SQL) Customer table with Customer’s id, name, address, city as varchar, customer’s date of birth as date type and zip code number where the customers id is the primary key in the table, name and date of birth are mandatory. Id has a 10-character limit, name, address and city have a 50-character limit, zip has a 5-character limit Product Table with Product id, description and finish as varchar, price...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT