primary-key

primary key and foreign key

丶灬走出姿态 提交于 2019-12-02 07:56:09
问题 I have 3 tables Student Loan Book - StudentID LoanID BookID which foreign keys do i need to set so when given the student name, search all loan from that student and display the book detail 回答1: Here's a start with such vague requirements: CREATE TABLE dbo.Students ( StudentID INT PRIMARY KEY -- , other columns about students ); CREATE TABLE dbo.Loans ( LoanID INT PRIMARY KEY, StudentID INT NOT NULL FOREIGN KEY REFERENCES dbo.Students(StudentID) -- , other columns about loans ); CREATE TABLE

Access Primary Key usage/role

巧了我就是萌 提交于 2019-12-02 07:50:07
My question is in relation to connecting a VB.net project to an Access DB. Must I have a primary key in my table, or have is there a way to alter my code to not look for a PK? I have an error popping up telling me that I have no primary key. Now if i make "AdminID" my primary key, the system works. I was just questioning as to whether or not this is required? Currently my combobox displays "AdminID" where as I would rather it display "AdminName" Thanks. Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= InfoSystem.accdb") Dim objAdminDA As New OleDb

SQL primary key constraint although record does not exist

偶尔善良 提交于 2019-12-02 07:18:50
问题 I am getting the following error: Violation of PRIMARY KEY constraint 'PK_ss_student_grade'. Cannot insert duplicate key in object 'dbo.ss_student_grade'. The duplicate key value is (301, 1011, 24801, 33). If I check the table before the insert there are no records with such a primary key. The insert is done through C# code and I made sure that the code runs only once. even after the error if I check the table I still get no record with such a primary key. Note: a trigger runs on the insert

Some sort of “different auto-increment indexes” per a primary key values

不羁岁月 提交于 2019-12-02 06:52:23
I have got a table which has an id (primary key with auto increment), uid (key refering to users id for example) and something else which for my question won’t matter. I want to make, lets call it, different auto-increment keys on id for each uid entry. So, I will add an entry with uid 10, and the id field for this entry will have a 1 because there were no previous entries with a value of 10 in uid . I will add a new one with uid 4 and its id will be 3 because I there were already two entried with uid 4 . ...Very obvious explanation, but I am trying to be as explainative an clear as I can to

Don't use deleted primary keys

拥有回忆 提交于 2019-12-02 05:06:10
问题 Insert id 1 and 2. Remove id 2. Insert new row, it gets id 2 instead of 3. How do I change this? I don't want to reuse primary keys. import sqlite3, os os.remove('mydatabase.db') conn = sqlite3.connect("mydatabase.db") # or use :memory: to put it in RAM cursor = conn.cursor() # create a table cursor.execute("CREATE TABLE if not exists albums (id INTEGER PRIMARY KEY NOT NULL, title text, artist text, release_date text, publisher text, media_type text)") cursor.execute("CREATE TABLE if not

Meaning of @GeneratedValue with strategy of TABLE

心已入冬 提交于 2019-12-02 04:49:32
问题 The JPA specification gives the following explanation of the annotation @GeneratedValue(strategy=TABLE) : The TABLE generator type value indicates that the persistence provider must assign primary keys for the entity using an underlying database table to ensure uniqueness. But what does "using an underlying database table" mean in practice? Does it mean using an auxiliary table? Or by scanning the entity-table to find an ID not in use? Or something else? 回答1: Check out JavaDoc for

primary key and foreign key

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:49:00
I have 3 tables Student Loan Book - StudentID LoanID BookID which foreign keys do i need to set so when given the student name, search all loan from that student and display the book detail Here's a start with such vague requirements: CREATE TABLE dbo.Students ( StudentID INT PRIMARY KEY -- , other columns about students ); CREATE TABLE dbo.Loans ( LoanID INT PRIMARY KEY, StudentID INT NOT NULL FOREIGN KEY REFERENCES dbo.Students(StudentID) -- , other columns about loans ); CREATE TABLE dbo.Books ( BookID INT PRIMARY KEY, -- , other columns about books ); CREATE TABLE dbo.StudentBooks (

Possible to condense primary key/serial?

半城伤御伤魂 提交于 2019-12-02 03:55:03
问题 I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out.. Well, Lets say I have Table1 and Table2. Table1 has 3 fields. RID, table2_rid,data So table1.table2_rid references table2.RID and this is expressed with a foreign key. In both the RID field is the primary key and is a serial type. What I would like to know is how to "condense" the primary keys? Like say you add 5 records and deleted record number 3. Your primary keys

SQL primary key constraint although record does not exist

跟風遠走 提交于 2019-12-02 03:20:39
I am getting the following error: Violation of PRIMARY KEY constraint 'PK_ss_student_grade'. Cannot insert duplicate key in object 'dbo.ss_student_grade'. The duplicate key value is (301, 1011, 24801, 33). If I check the table before the insert there are no records with such a primary key. The insert is done through C# code and I made sure that the code runs only once. even after the error if I check the table I still get no record with such a primary key. Note: a trigger runs on the insert in the table but it only writes to a log file and does not affect any data in the database What could

Oracle Materialized Views with primary key

淺唱寂寞╮ 提交于 2019-12-02 02:52:08
问题 I created the Oracle Materialized View below: CREATE MATERIALIZED VIEW MyMV REFRESH COMPLETE ON DEMAND AS SELECT t1.* FROM table1 t1, table2 t2 where t1.id=t2.id; The table1 has a primary key and the MV was created succesfully but the primary key was not created in the materialized view table. Is there any other way to create MVs with primary keys? 回答1: it's because your materialized view is based on two tables, if you create your view based on a single table with a primary key, then the