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


Create Table


Create Table

Author
Message
Miles Neale
Miles Neale
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5578 Visits: 1695
Nice one for a Friday.

Thanks!

Not all gray hairs are Dinosaurs!
malleswarareddy_m
malleswarareddy_m
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3401 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 (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)

Group: General Forum Members
Points: 369 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
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

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

Malleswarareddy
I.T.Analyst
MCITP(70-451)
kapil_kk
kapil_kk
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8299 Visits: 2777
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
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2079 Visits: 180
Nice question...
vinu512
vinu512
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6409 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.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3867 Visits: 1221
Good Question. Thanks.
manik_anu
manik_anu
SSC Eights!
SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)

Group: General Forum Members
Points: 846 Visits: 319
nice and easy question....

Manik
You cannot get to the top by sitting on your bottom.
sqlnaive
sqlnaive
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8797 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