I have two different things to happen at once.., basically I need to insert two new records in a table if they are not already there... and for sure they will always have the same ID and Name (i did this) but then immediately after that i need to check if a table existst and if it does not create it.. (but if it does exist I DO NOT want to drop it just leave it alone).
Please see my code below.. Can you help me with the checking of the table existing or not? and if you see a room on improvement please do..
Thank you
--ADD LOCKS
BEGIN TRAN
IF EXISTS (SELECT myID, myName
FROM myTable
WHERE myID = 7 AND myName = 'Pedro')
SELECT 1
ELSE
INSERT INTO myTable (myID , myName) values ( 7, 'Pedro')
IF EXISTS (SELECT myID, myName
FROM myTable
WHERE myID = 8 AND myName = 'Joseph')
SELECT 1
ELSE
INSERT INTO myTable (myID , myName) values ( 8, 'Joseph')
COMMIT
--NOW BELOW I WANT TO DO THE CREATION OF A TABLE IF IT DOES NOT EXIST
NOT SURE HOW TO CHECK IT.. BUT KNOW HOW TO CREATE IT
--IF TABLE DOES NOT EXIST DO THE FOLLOWING
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[myTable](
[myID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar(MAX)] NOT NULL
CONSTRAINT [PK_myTable] PRIMARY KEY CLUSTERED
(
[myID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--ELSE DONT DO NOTHING