Ger Creer
Ger Creer

Reputation: 11

visual studio/ microsoft sql error for relational keys

CREATE TABLE TBLUSER_INFO
(
ID INT IDENTITY(1,1)not null PRIMARY KEY,
LNAME VARCHAR(50)not null,
FNAME VARCHAR(50)not null,
MNAME VARCHAR (50)not null,
ADDRESS VARCHAR(50)not null,
AGE INT not null,
GENDER VARCHAR(10)not null,
CONTACTNO varchar(50) not null, 
BIRTHDATE datetime
);


CREATE TABLE TBLUSER_ACCOUNT
(
ID INT FOREIGN KEY REFERENCES TBLUSER_INFO(ID) ,
USERNAME VARCHAR(50)not null,
USERPASS NVARCHAR(50)not null,
SECURITYQUESTION VARCHAR(max)not null,
SECURITYANSWER VARCHAR(50)not null
);

the error is this

DBML1011: The Type element 'TBLUSER_ACCOUNT' contains the Association element 'TBLUSER_INFO_TBLUSER_ACCOUNT' but does not have a primary key.  No code will be generated for the association.

when I run my system in visual, this will be the output my system

PLS HELP ME FOR MY PROJECT. IM DESPERATE

Upvotes: 0

Views: 39

Answers (2)

M. Wiśnicki
M. Wiśnicki

Reputation: 6203

In your TBLUSER_ACCOUNT need to add primary key ID and fkey with TBLUSER_INFO id, like this.

 CREATE TABLE TBLUSER_INFO
    (
    ID INT IDENTITY(1,1)not null PRIMARY KEY,
    LNAME VARCHAR(50)not null,
    FNAME VARCHAR(50)not null,
    MNAME VARCHAR (50)not null,
    ADDRESS VARCHAR(50)not null,
    AGE INT not null,
    GENDER VARCHAR(10)not null,
    CONTACTNO varchar(50) not null, 
    BIRTHDATE datetime
    );

    CREATE TABLE TBLUSER_ACCOUNT
    (
    ID INT IDENTITY(1,1) not null PRIMARY KEY,
    ID_TBLUSER_INFO INT,
    USERNAME VARCHAR(50)not null,
    USERPASS NVARCHAR(50)not null,
    SECURITYQUESTION VARCHAR(4000) not null,
    SECURITYANSWER VARCHAR(50)not null,
    FOREIGN KEY (ID_TBLUSER_INFO) REFERENCES TBLUSER_INFO(ID)
    );

Upvotes: 0

apomene
apomene

Reputation: 14389

SQL SERVER requires to have a primary key in your table before you declare any foreign keys.

Here you can see why.

Upvotes: 1

Related Questions