Question

-What happens if you attempt to insert an existing value into the primary key. After insertion you must change the value to a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

The DBMS will not allow you to insert

Explanation

Primary Key

A primary key used for the purpose of uniquely identifiying each record in a database table.

Primary keys must contain "UNIQUE" values

Primary keys cannot contain NULL value

Example


/* Create a table called NAMES */
CREATE TABLE NAMES(Id integer PRIMARY KEY, Name text);

/* Create few records in this table */
INSERT INTO NAMES VALUES(1,'Tom');
INSERT INTO NAMES VALUES(1,'Lucy');


/* Display all the records from the table */
SELECT * FROM NAMES;

if you observe that in the query we are trying to insert '1' again lets run the query and see the result

/* Create a table called NAMES */ CREATE TABLE NAMES(ID integer PRIMARY KEY, Name text); $sqlite3 database. sdb < main.sql 1

As you can see there is an error

"UNIQUE" constraint failed

WN /* Create a table called NAMES */ CREATE TABLE NAMESCID integer PRIMARY KEY, Name text); $sqlite3 database. sdb < main.sql

Now we changed the value '1' to '2'

now query runs perfectly

Hence, The DBMS will not allow you to insert

---

Add a comment
Know the answer?
Add Answer to:
-What happens if you attempt to insert an existing value into the primary key. After insertion...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys...

    Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys Exercise                                                                                In Lab 09, we will continue the practice of creating tables. You will need to write SQL statements for the tasks specified below. After you complete them, submit your SQL script (in one *.sql file) to Blackboard by 11:59pm Nov. 16 (Friday). Include your name as a comment in the SQL script submitted. The creation statement for each table is worth one point,...

  • You are designing a table for employee data of a company. You have a requirement to...

    You are designing a table for employee data of a company. You have a requirement to identify if an employee is a United States citizen or not. You have designed a table called EMPLOYEE to store information related to each employee and you have a column called US CITIZEN INDICATOR to store if an employee is a US citizen or not. You only want to store values "Y" or "N" in this column. From the following options, what is the...

  • CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT...

    CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'SPORTS','NEW YORK'); INSERT INTO DEPT VALUES (20,'HOME','DALLAS'); INSERT INTO DEPT VALUES (30,'OUTDOOR','CHICAGO'); INSERT INTO DEPT VALUES (40,'CLOTHING','BOSTON'); CREATE TABLE EMP ( EMPNO INTEGER NOT NULL, ENAME VARCHAR(10), JOB VARCHAR(9), MGR INTEGER, SAL FLOAT, COMM FLOAT, DEPTNO INTEGER NOT NULL, FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO), FOREIGN KEY (MGR) REFERENCES EMP(EMPNO), PRIMARY KEY (EMPNO)); INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL, 5000,NULL,10); INSERT INTO...

  • 1. How do you insert a “break point” in your script? 2. What happens to the...

    1. How do you insert a “break point” in your script? 2. What happens to the execution of a script when MATLAB encounters a break point? Is the execution ended? 3. What happens if a break point is inserted within a loop (like a for loop)? 4. How do you step through different lines of the code during the debugging session? 5. How can you see the values of a particular variable when the debug session is active? 6. Are...

  • Must be written in C 89 Mode Array Insertion Your task is to complete the implementation...

    Must be written in C 89 Mode Array Insertion Your task is to complete the implementation of the insertion function, insert_into_array: int* insert_into_array(int arr[], size_t arr_len, int value, size_t pos); The insertion function inserts a value into an array at a specified position. All elements to the right of the inserted element are shifted over a position (upon inserting, all elements at the insertion position are shifted up an index, and the last element in the array is overwritten by...

  • The employee is table, the best candidate for primary key is Select one: a. Department ID...

    The employee is table, the best candidate for primary key is Select one: a. Department ID b. Employee hiredate c. Employee ID d. Employee salary Question 2 A primary key can be composed of more than one attribute. Select one: True False Question 3 A foreign key allows you to join two tables. Select one: True False Question 4 Given two tables, department (dept_id, dept_location, dept_name) and EMPLOYEE(emp_id, emp_name, emp_dept_id, emp_name, emp_salary), which attribute (column) is the foreign key? Select...

  • What would you change your attitude about after studying health navigators, the primary care medical home,...

    What would you change your attitude about after studying health navigators, the primary care medical home, and the green house Project?

  • What happens when you try to compile and run the following code? String query = "INSERT...

    What happens when you try to compile and run the following code? String query = "INSERT INTO Invoices (InvoiceDate InvoiceTotal) "              + "VALUES ('2/10/01', '443.55')"; Statement statement = connection.createStatement(); statement.executeUpdate(query); a. A SQLException is thrown at runtime because the executeUpdate method can’t accept a String object. b. A SQLException is thrown at runtime because the SQL statement is coded incorrectly. c. An error occurs at compile time because the SQL statement is coded incorrectly. d. This code compiles and...

  • Problem 3​ Hashing The HashTable class implemented in chapter 5 of your online textbook exhibits undesirable behavior if you use put(key,val) to add a new key-value pair when the table is full. Re-imp...

    Problem 3​ Hashing The HashTable class implemented in chapter 5 of your online textbook exhibits undesirable behavior if you use put(key,val) to add a new key-value pair when the table is full. Re-implement the put method so that the table will automatically increase in size when the method detects that the table is full. The new size should be a prime number that approximately twice the current size of the table. For example, if the original size is 11, the...

  • What do you think happens to the value of the Law Enforcement Oath of Honor when...

    What do you think happens to the value of the Law Enforcement Oath of Honor when the very ones that we trust to serve and protect us, becomes the very ones that we fear the most? Furthermore, how do you think Americans look at police departments in North America after incidents of police misconduct, much like in New Orleans, and other cities in this country such as Los Angeles, New York, New Orleans and Chicago, just to name a few.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT