Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

I'm having trouble adding a column to my table.

$
0
0

I created a table with three columns in it: 

UserId, password and username. However, I want to add in a fourth column for the GUID. 

I'm incredibly new to SQL so I apologize if the problem turns out to be plain and clear. 

IF NOT EXISTS (SELECT *
                 FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE TABLE_SCHEMA = 'dbo'
                 AND  TABLE_NAME = 'Users'
				 AND  COLUMN_NAME = 'userGuid')

Begin

CREATE TABLE [Users](
    [UserId] [int] IDENTITY(1,1) NOT NULL,
    [username] [varchar](50) NOT NULL UNIQUE,
    [password] [varchar](50) NOT NULL
	/*userGuid uniqueidentifier NULL*/
)


ALTER TABLE Users  Add userGuid uniqueidentifier NULL

END

Someone suggested I try adding in a 'Commit Statement'. 

I placed the commit statement in between the 'ALTER TABLE Users' statement and the 'END' Statement. 

I execute both across my table, flip over to the DESIGN view, still nothing. I have my three columns but not the fourth. 

This relates to an error I'm getting in VS: 'Invalid Column name 'userGuid'', but I won't get into that because I'm almost certain that the issue is that I don't actually have a userGuid column. 


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>