Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 CREATE A DATABASE

Author  Topic 

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-06-20 : 22:50:25
Hi Guys and Geeks,

Hope you will read and comment to me on this, I have been asked to create a Database, with a minimun of 5 tables, and it may grow as the days go by.

These 5 tables are to be created now with primary and foriegn key relationships.

Indexing will be done later.

Need the kickstart, I know to do it, but the efficient way for the primary and foreign key relationships.

Thanks,

Antonio

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-20 : 22:55:33
didnt understand what you mean by efficient way. Are you asking a design approach or syntax as such for PK FK creation?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-06-20 : 23:48:31
The efficient way is the normal way, which I should follow, in creating the tables and the database, yes the design approach and the primary, foreign key approach would be needed as an advicce..

for example, I know how to create a database and create a table, without investigating or googling, however I would like to follow the rules in having this DB a flexible one, which could be used in a long run..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-21 : 00:20:11
what do you mean by having DB flexible one? generally you will create fks in tables which need to refer to master table and link it to its pk column

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-06-21 : 01:40:10
Just the way how you guys create a database with some tables, now let me tell the scenario

Thank you for reading the post

1) Table names - Merchant, Deal, OrderDeals, Returns, Order

Merchant(1) to Deal(M) - relationship (1 to many)
Returns (1) to Order(M) - relationship (1 to many)

Order(M) to Deal(M) - relationship (Many to Many)

in the above case of many to many, we bring the orderdeals table

Order(1) to OrderDeals(M) - relationship (1 to Many)
Deal(1) to OrderDeals(M) - relationship (1 to Many)

Can you help me in doing this now..

Thanks,

AB
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-21 : 18:13:41
[code]
CREATE TABLE Merchant
(
MerchantID int IDENTITY(1,1) PRIMARY KEY,

other columns...
)



CREATE TABLE Deal
(
DealID int IDENTITY(1,1) PRIMARY KEY,

other columns...
)



CREATE TABLE Order
(
OrderID int IDENTITY(1,1) PRIMARY KEY,

other columns...
)


CREATE TABLE MerchantDeals
(
MerchantDealID int IDENTITY(1,1) PRIMARY KEY,
MerchantID int REFERENCES Merchant (MerchantID),
DealID int REFERENCES Deal (DealID)
...
)


CREATE TABLE OrderReturn
(
OrderReturnID int IDENTITY(1,1) PRIMARY KEY,
OrderID int REFERENCES Order (OrderID),
ReturnID int REFERENCES Return (ReturnID)
...
)

CREATE TABLE OrderDeals
(
OrderDealID int IDENTITY(1,) PRIMARY KEY,
OrderID int REFERENCES Order (OrderID),
DealID int REFERENCES Deal (DealID)
...
)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-06-25 : 21:05:36
Thanks mate, how about the constraints, dont I have to add those..
Go to Top of Page
   

- Advertisement -