Question

In: Computer Science

. Please write the SQL statements required to create the following relations, including appropriate versions of...

. Please write the SQL statements required to create the following relations, including appropriate versions of all primary and foreign key integrity constraints. (10 points)
Books (isbn:CHAR(10), title: CHAR(20), author: CHAR(80), qty_in_stock: INTEGER, price: REAL, year_published: INTEGER)
Customers (cid:INTEGER, cname: CHAR(80), address: CHAR(200))
Orders (ordernum:INTEGER, cid:INTEGER, order_date: DATE, cardnum:CHAR(16))
Orderlists (ordernum:INTEGER, isbn:CHAR(10), qty:INTEGER, ship_date:DATE)

Solutions

Expert Solution

create database book_store;
use book store;
 

create table Books(isbn CHAR(10),title CHAR(20),author CHAR(80),qty_in_stock int,price REAL,year_published int);

insert into Books values('aaaaa','ABC','ggh',10,10000,2011)

alter table Books add primary key(isbn);

desc Books;



create table customers(cid int,cname VARCHAR(80),address VARCHAR(200));

insert into customers values(1,'Alex','xahsdsad');

alter table customers add primary key(cid);

desc customers;




create table orders(ordernum int,cid int,order_date DATE,card_num VARCHAR(16));

insert into orders values(444,1970,11/06/20,'xxxxxxxxx')

alter table orders add primary key(ordernum);

desc orders;


create table orderlist(ordernum int,isbn CHAR(10),qty int,ship_date DATE);

insert into orderlist values(444,'aaaaa'10,12/06/20);

alter table orderlist add foreign key(ordernum) references ordernum(cid);





select * from table_name;


example: select * from table Books;

 


Hello student you can insert more records in the table as you required , if you have any query related to this sql query please feel free to contact me .

Thankyou.


Related Solutions

Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create a login for AdventureWorks employees. An employee login should be composed of the first letter of a person's first name combined with their last name. In addition, the login should be all lower case characters. All the required information is located in Person.Person table. Employees can be identified by "EM" value in the PersonType field. The output should include BusinessEntityID, first name (FirstName), last...
Create one sql script file to complete the following. You cannot run separate SQL statements for...
Create one sql script file to complete the following. You cannot run separate SQL statements for the homework. You will also need to place a semicolon after each SQL statement, a requirement for SQL files containing multiple SQL statements Lesson 3 Write a query to display the current date. Label the column DATE. Display the last name of all employees who have an A and an E in their last name. For each employee, display the employee number, last_name, salary,...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
Develop the SQL scripts that will create the tables and enforce all the appropriate constraints •...
Develop the SQL scripts that will create the tables and enforce all the appropriate constraints • Develop sample SQL scripts that will insert the data to the database (one row in each table) • Convert at least 2 entities to MongoDB Collections. Write the scripts that will Create the collection(s)
Write and run SQL statements to complete the following tasks Show the details of the employees...
Write and run SQL statements to complete the following tasks Show the details of the employees who are located in area code 901 and their manager employee number is 108. Show the details of the employees who are also mangers. Show the details of the customers whose balance is greater than 220 but less than 500. Show the details of the customers whose balance is highest. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint...
1. Use SQL to create a polyinstantiated table including a primary key and a unique constraint 2.Use SQL to insert multiple records for each security classification with the same ID. You must have 4 classifications. 3.Use SQL to create 4 schemas, one for each security classification 4.Use SQL to create a view in each schema that restricts the records to those belonging to a particular security classification and restricts the columns to only those columns that have relevant data. 5.Select...
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate...
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate constraints except FOREIGN KEY constraints. For filename, use CREATE.sql accordingly. Import data from the csv files to EMP, DEPT, and PROJ tables. Check that all data for EMP, DEPT, and PROJ tables has been imported. __________________________ employees.csv empNo,fname,lname,address,sex,salary,position,deptNo 1000,Steven,King,"731 Fondren, Houston, TX",M,30000,Programmer,60 1007,Diana,Lorentz,"638 Voss, Bellaire, TX",F,24000,Clerk,20 2002,Pat,Fay,"3321 Castle, Spring, TX",F,15000,Sales Representative,80 1760,Jonathan,Taylor,"561 Rice, Houston, TX",M,60000,Manager,20 1740,Ellen,Abel,"890 Stone, Houston, TX",F,65000,Manager,60 2060,William,Gietz,"450 Berry, Bellaire, TX",M,65000,Manager,80 2000,Jennifer,Whalen,"980...
Write and run SQL statements to complete the following tasks. Show customer 10014’s name and the...
Write and run SQL statements to complete the following tasks. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number of units of each. Add a new attribute (column) engaged varchar(3) to the customer table and update the engaged attribute for the customers who have not generated any invoice to ‘No’. Task 2 should be completed in two steps i.e. two SQL commands. Sql file -- Creating Tables .headers on .mode column .separator , DROP TABLE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT