| | |
URGENT!! Need help regarding primary key!!
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 22
Reputation:
Solved Threads: 0
I have converted around 395 Excel survey forms to MS SQl database with that many tables. Well, I run a script to assign a primary key on all the tables on my database.First I set the column property to NOT NULL and then i assign the primary key to it. I assign the primary key to a column called 'FPC_Code'. This column contains values such as, _C2348787, _C567489 etc etc......Well, my problem is that THE SECOND I ASSIGN THE PRIMARY KEY TO ALL THE TABLES THEY GET SORTED WRT THE FPC_Code column. I dont want this sorting to take place. I need it to remain unsorted as they are survey forms and would like to preserve the order. I am running out of time and i seriously need help. This is the script I run on all the tables on my database.
ALTERING COLUMN TO NOT NULL
ASSIGNING PK
ALTERING COLUMN TO NOT NULL
MS SQL Syntax (Toggle Plain Text)
DECLARE Alter_tables_cursor CURSOR FOR SELECT table_name FROM information_schema.TABLES WHERE table_name<>'dtProperties' AND table_type<>'VIEW' OPEN Alter_tables_cursor DECLARE @tablename sysname FETCH NEXT FROM Alter_tables_cursor INTO @tablename WHILE ( @@FETCH_STATUS = 0 ) BEGIN PRINT 'Altering NOT NULL --> '+@tablename+' ' EXEC('ALTER TABLE '+@tablename+' ALTER COLUMN FPC_CODE varchar(255) NOT NULL') FETCH NEXT FROM Alter_tables_cursor INTO @tablename END PRINT 'All user-defined tables have been Altered.' DEALLOCATE Alter_tables_cursor
ASSIGNING PK
MS SQL Syntax (Toggle Plain Text)
DECLARE Alter_tables_cursor CURSOR FOR SELECT table_name FROM information_schema.TABLES WHERE table_name<>'dtProperties' AND table_type<>'VIEW' OPEN Alter_tables_cursor DECLARE @tablename sysname FETCH NEXT FROM Alter_tables_cursor INTO @tablename WHILE ( @@FETCH_STATUS = 0 ) BEGIN PRINT 'Altering Primary Key -->'+@tablename+' ' EXEC('ALTER TABLE '+@tablename+' ADD PRIMARY KEY (FPC_Code)') FETCH NEXT FROM Alter_tables_cursor INTO @tablename END PRINT 'All user-defined tables have been Altered.' DEALLOCATE Alter_tables_cursor
Last edited by peter_budo; Nov 28th, 2008 at 1:40 pm. Reason: Correcting closing code tags from [\code] to [/code]
![]() |
Similar Threads
- HTML with VB.NET need help urgent (VB.NET)
- list contraints of access table using vb.net 2005 (VB.NET)
- Need urgent help. Problem with SQL and win server. (Windows NT / 2000 / XP)
- Asp.net Sql Query (ASP.NET)
- How to pass querystring to crystal report (Visual Basic 4 / 5 / 6)
- help me its urgent! (Visual Basic 4 / 5 / 6)
- plz urgent urgent urgent help plz (PHP)
- Long ado net question but urgent help required (ASP.NET)
- plz help me to connect more than one table in the ms access database to the asp.net (ASP.NET)
Other Threads in the MS SQL Forum
- Previous Thread: Return database that a trigger was executed in
- Next Thread: Please help
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger getdate highperformancecomputing hpc hpcserver2008 ibm iis limit loop maximum microsoft ms mssql multiple multithreading news number permission position query reporting result server services sets single source sql sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





