Question

In: Computer Science

DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...

DBMS Create/Insert/Update SQL

I need the create, insert, and update SQL statement for this table:

Customer
PK Customer ID Text
Phone Number int
name text
address ID int
email text
FK vendor ID int

Vendor is the name of the table the FK comes from.

Solutions

Expert Solution

Create command

create table customer(customer_id varchar(10) primary key, phone_number int,
name varchar(15), address_id int, email varchar(20), vendor_id int references vendor(vendor_id));

output:

Table created.


SQL> desc customer;
Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_ID NOT NULL VARCHAR2(10)
PHONE_NUMBER NUMBER(38)
NAME VARCHAR2(15)
ADDRESS_ID NUMBER(38)
EMAIL VARCHAR2(20)
VENDOR_ID NUMBER(38)

Text datatypes can be termed as varchar type in oracle. So we are using varchar types for text attributes in oracle. for the successful creation of the customer table Vendor table must be created first as vendor_id is a foreign key referencing vendor table;

Insertion command for customer table:


SQL> insert into vendor(vendor_id) values(1234);

output:

1 row created.

SQL> insert into customer values('C001', 8297435672, 'Scott', 707, '[email protected]', 1234);

output:

1 row created.


SQL> select * from customer;

CUSTOMER_I PHONE_NUMBER NAME ADDRESS_ID EMAIL VENDOR_ID
---------- ------------ --------------- ---------- -------------------- ----------
C001 8297435672 Scott 707 [email protected] 1234

For inserting a row into customer table we need to provide value for the vendor_id attribute which is a foreign key referencing vendor table. So the value of the vendor_id must exist in the vendor table before we insert it into customer table. Therefore in the above insert statement we first inserted a value into the vendor_id attribute of vendor table then insert a new row into the customer table with that vendor_id;

update statement:

Suppose we want to update the name of a customer in customer table:

SQL command

SQL> update newcustomer set name='Bob' where name='Scott';

1 row updated.

SQL> select * from customer;

CUSTOMER_I PHONE_NUMBER NAME ADDRESS_ID EMAIL VENDOR_ID
---------- ------------ --------------- ---------- -------------------- ----------
C001 8297435672 Bob 707 [email protected] 1234

update command updates the row/rows in which the where condition satisfies and sets the attribute mentioned in the query to a value provided.

[ N.B: if you face any difficulty in understanding please contact through comments.]


Related Solutions

DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Use a single SQL statement to create a relational table and to load into the table...
Use a single SQL statement to create a relational table and to load into the table department name, subject code, year of running and session of running that offered by the departments. Note that a running subject offered by a department means a lecturer of the department has been assigned to teach the subject. Next, enforce the appropriate consistency constraints on the new table.    When ready use SELECT statement to list the contents of the relational table created and...
project on hotel management in dbms with er diagram and table (sql) please give answer
project on hotel management in dbms with er diagram and table (sql) please give answer
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
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 three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
I need to create a multi step income statement and statement of retained earnings with the...
I need to create a multi step income statement and statement of retained earnings with the following information ( assume a 30% tax rate and 500,000 shares of common stock) Accounts Receivable                       $555,000 Accumulated Depr.-equipment          450,000 Accumulated Depr.-buildings            360,000 Allowance for doubtful accts.              36,000 Common Stock                           2,000,000 Depreciation Expense (equipment)      50,000 Depreciation Expense (buildings)         60,000 Dividends (common stock)               120,000 Dividends Payable                            30,000 Insurance Expense                             35,000 Interest Expense                               40,000 Interest Payable                          ...
I need to create a multi step income statement and statement of retained earnings with the...
I need to create a multi step income statement and statement of retained earnings with the following information ( assume a 30% tax rate and 500,000 shares of common stock) Accounts Receivable                       $555,000 Accumulated Depr.-equipment          450,000 Accumulated Depr.-buildings            360,000 Allowance for doubtful accts.              36,000 Common Stock                           2,000,000 Depreciation Expense (equipment)      50,000 Depreciation Expense (buildings)         60,000 Dividends (common stock)               120,000 Dividends Payable                            30,000 Insurance Expense                             35,000 Interest Expense                               40,000 Interest Payable                          ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT