Is it a good idea to store phone number as a primary key on RDBMS? They are unique to nearly all of us. But my friend suggests it is not a good idea because of the following reasons. What if two …
Tag: primary-key
What is the impact of altering a table and making an Identity column the Primary key?
I am fixing issues on a new database, set up by a third party. SIDE NOTE: I have just joined the company that originally hired the third party. The new database is less than two weeks old and was …
Oracle not auto-generating primary key on insert
New to Oracle here. I have a table created with the following SQL: create table Widgets ( id integer constraint pkWidgets primary key using index, ruleId integer not …
SQL: Having a primary key also be a foreign key
For this question, I am referring to the specific case where you have table T, it has primary key K, but K is a foreign key. Is this valid? And how would you write it in SQL99? All the other …
Why we need a primary key?
I am reading about primary keys and at a lot of tutorials, technical blogs etc., and I found that a primary key cannot be null. I think it’s totally wrong because I was able to insert null value in the column. I suppose a primary key can have a not null value only if the column is declared as not
Retrieve Oracle last inserted IDENTITY
Since Oracle 12c we can use IDENTITY fields. Is there a way to retrieve the last inserted identity (i.e. select @@identity or select LAST_INSERTED_ID() and so on)? Answer Well. Oracle uses sequences and default values for IDENTITY functionality in 12c. Therefore you need to know about sequences for your question. First create a test identity table. First, lets find your
java.sql.SQLException: Field ‘id’ doesn’t have a default value
I am trying to insert data into arrivaltimes tables but I am getting the following error: java.sql.SQLException: Field ‘id’ doesn’t have a default value Answer You are missing AUTO INCREMENT for Primary Key in arrivaltimes table. Just need to add AUTO_INCREMENT while creating table
Can I use VARCHAR as the PRIMARY KEY?
I have a table for storing coupons/discounts, and I want to use the coupon_code column as the primary key, which is a VARCHAR. My rationale is that, each coupon will have a unique code, and the only commands I will be running are SELECT … FROM … WHERE coupon_code=’..’ I won’t be doing any joins or indexing, and I don’t
Difference between primary key and unique key
I’m using a MySQL database. In which situations should I create a unique key or a primary key? Answer Primary Key: There can only be one primary key constraint in a table In some DBMS it cannot be NULL – e.g. MySQL adds NOT NULL Primary Key is a unique key identifier of the record Unique Key: Can be more
How can I alter a primary key constraint using SQL syntax?
I have a table that is missing a column in its primary key constraint. Instead of editing it through SQL Server, I want to put this in a script to add it as part of our update scripts. What syntax can I use to do this? Must I drop and recreate the key constraint? Answer Yes. The only way would