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.
| Author |
Topic |
|
Newbie2SQL
Starting Member
1 Post |
Posted - 2008-03-31 : 12:07:57
|
| Hello to all,I know homework questions are frowned upon and am not looking for a professional to all of my work (just a bit of insight). I know they are: if, from, and where, but I have done a bit of research and am having trouble exactly defining these two questions. What is the purpose of these two statements and why are they needed?if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[Employee]GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Job_title]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[Job_title]GOThanks in advance! |
|
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-03-31 : 12:11:12
|
| The drop command will return an error if the table does not exist.Yhe if checks for existence and then drops the table if it finds it."God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-03-31 : 12:20:30
|
| Also, you have to go thru the sysobjects table, if you tried IF exists(select * from yourtable) you'd still get an Object does not exist error.JimP.S.People here don't particulary mind homework questions. What we mind is when the person tries to fool us into doing their homework for them, without any effort on their part. |
 |
|
|
|
|
|