SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create Table


Create Table

Author
Message
Miles Neale
Miles Neale
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3458 Visits: 1694
Nice one for a Friday.

Thanks!

Not all gray hairs are Dinosaurs!
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2365 Visits: 1189
Thanks for nice question.

---Statement 1
CREATE TABLE #table1
(
ID int PRIMARY KEY,
Name varchar(20)
CONSTRAINT UN_Name UNIQUE(Name)
);
CREATE TABLE #table2
(
ID int PRIMARY KEY,
PersonName varchar(30) REFERENCES #table1(Name)
);
go
select * from #table1
select * from #table2

drop table #table1
The above code will not throw error. Because the length of the data type for column PersonName in second table is greater than the length of first table column Name

Malleswarareddy
I.T.Analyst
MCITP(70-451)
michaelhitchin
michaelhitchin
Old Hand
Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)Old Hand (365 reputation)

Group: General Forum Members
Points: 365 Visits: 81
malleswarareddy_m (4/26/2013)
Thanks for nice question.

---Statement 1
CREATE TABLE #table1
(
ID int PRIMARY KEY,
Name varchar(20)
CONSTRAINT UN_Name UNIQUE(Name)
);
CREATE TABLE #table2
(
ID int PRIMARY KEY,
PersonName varchar(30) REFERENCES #table1(Name)
);
go
select * from #table1
select * from #table2

drop table #table1
The above code will not throw error. Because the length of the data type for column PersonName in second table is greater than the length of first table column Name

Well, I think that the reason that your script runs is not because of the wider foreign key column. I think it's because you used temporary tables and they don't enforce foreign key constraints.
malleswarareddy_m
malleswarareddy_m
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2365 Visits: 1189
Yes you are right.I have verified with temp table.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
kapil_kk
kapil_kk
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3662 Visits: 2766
malleswarareddy_m (4/26/2013)
Thanks for nice question.

---Statement 1
CREATE TABLE #table1
(
ID int PRIMARY KEY,
Name varchar(20)
CONSTRAINT UN_Name UNIQUE(Name)
);
CREATE TABLE #table2
(
ID int PRIMARY KEY,
PersonName varchar(30) REFERENCES #table1(Name)
);
go
select * from #table1
select * from #table2

drop table #table1
The above code will not throw error. Because the length of the data type for column PersonName in second table is greater than the length of first table column Name

+1 :-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Bangla
Bangla
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1751 Visits: 180
Nice question...
vinu512
vinu512
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2153 Visits: 1626
Very good question.

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
David Conn
David Conn
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3259 Visits: 1158
Good Question. Thanks.
manik_anu
manik_anu
Mr or Mrs. 500
Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)

Group: General Forum Members
Points: 520 Visits: 312
nice and easy question....

Manik
You cannot get to the top by sitting on your bottom.
sqlnaive
sqlnaive
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4879 Visits: 2774
That was an easy question without any complexities. Thanks. :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search