문제

I have a table

                                            Moon PIS
    pID        pAddr        cID        cName        leaseExp        mRent        oID        oName        oContact

    pID – property id: coded to identify the specific property, chosen to be primary key.
    pAddr – property address, required (ie, cannot be null)
    cID – client id: coded to identify the client – null means not rented out yet
    cName – client name – null means not rented out yet
    leaseExp – lease Expiration date – null allowed, if not rented out yet.
    mRent – monthly rent (in dollars) – null allowed.
    oID – owner id: coded to identify the property owner, required (ie, cannot be null)
    oName – owner name, required (ie, cannot be null)
    oContact – owner’s contact address.

and I am suppose to normalize this table I created a table for the property, owner, and client. The property table has pID, pAddr the client table has cID, cName the owner table has oID, oName, oContact

first, I was wondering if normalized the table properly?

if so I am then required to move the data from the MoonPIS table into the newly created tables. I have attempted:

    INSERT INTO Property (PropertyID, PropertyAddr)
    SELECT pID, pAddr FROM Moon PIS

I am receiving an error saying "Microsoft Access database engine could not find the input table or query 'Moon'. Make sure it exist and that its name is spelled correctly."

Do I have to set up relationships prior to transferring the data. All I have done is created the tables and columns.

도움이 되었습니까?

해결책

You need to escape the name because it contains a space:

INSERT INTO Property (PropertyID, PropertyAddr)
    SELECT pID, pAddr
    FROM [Moon PIS];

다른 팁

This answer isn't valid for the question, as it refers to the original table, and not to the changes suggested in the question... but I'll leave it for now as I think it might be useful anyway, if someone disagrees I'll remove it.

first, I was wondering if normalized the table properly?

No, it's not properly normalized as it records data for multiple types of entites (properties, clients and owners). You'll want to move the client details (cName) and the owner details (oName and oContact) to their own tables (Client and Owner maybe) and just keep the cId and oID as foreign keys.

Also, what is this table supposed to record, right now you include a lot of data that doesn't depend on the primary key (propertyId). Take rent for example, is the rent bound to a property or is it something that relates to a specific contract with a client and can change depending on client? If so, it doesn't belong in the property table. And so on...

Normalizing relational designs can be hard (and involve formal logic), but if you want your design to work, it's a subject well worth putting some time into studying.

As for the query error, don't use white spaces in table names :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top