Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using sp_tableoption and getting an error.

Posted on 2004-08-09
7
Medium Priority
?
735 Views
Last Modified: 2010-08-05
Hi.

I am creating an SQL Script which will create a database.

The database is a conversion from a non SQL database.

A part of the script is ...

/****** Object:  Table [dbo].[AcceptCode]    Script Date: 09/08/2004 10:31:28 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AcceptCode]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AcceptCode]
GO

/****** Object:  Table [dbo].[AcceptCode]    Script Date: 09/08/2004 10:31:28 AM ******/
CREATE TABLE [dbo].[AcceptCode] (
      [UniqueID] [int] IDENTITY (1, 1) NOT NULL  ,
      [AcceptCode] nchar(3) ,
      [Description] nchar(40) ,
      [SummaryCode] nchar(3) ,
      [SpareText] nchar(17)
) ON [PRIMARY]
GO

 CREATE  UNIQUE  INDEX [PK_AcceptCode] ON [dbo].[AcceptCode]([UniqueID]) WITH  IGNORE_DUP_KEY  ON [PRIMARY]
GO

exec sp_tableoption 'AcceptCode', 'text in row', 'ON'

(I am cloning the script style that MS uses when you use Create Script on a database, so hopefully, my script will look the same as the one MS produces when I have finished).

When I run this script, the tables are produced as required.
The index is produced too.

But I get an error on the exec sp_tableoption line.

The error is ...

Server: Msg 2591, Level 16, State 90, Procedure sp_tableoption, Line 79
Could not find row in sysindexes with index ID 255 for table 'AcceptCode'.

This comes from the sp_tableoption procedure.

Line 79 is ...

            BEGIN TRAN
            DBCC LOCKOBJECTSCHEMA(@TableNamePattern)
            dbcc no_textptr(@TabId, @intOptionValue) <<<<<<<<<<<<<<<< Line 79
            COMMIT TRAN

I've just started with MS SQL Server, so I am not sure what I should be doing next.

Ideas/suggestions/etc.

Please.

Thank you.

Richard Quadling.
0
Comment
Question by:Richard Quadling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 280 total points
ID: 11751031
Hi Qualding,

<BOL>
sp_tableoption
Sets option values for user-defined tables. sp_tableoption may be used to turn on the text in row feature on tables with text, ntext, or image columns.
</BOL>

You table has no such field.

Text is a datatype
ALthough nchar can be used to store "text" - a string - , it's not TEXT datatype
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11751036
The TEXT IN ROW option is only for text datatypes. You don't have any columns which are text, they are all nchar, so you don't need the option. Infact, as is happening, you get an error if you try to set the option on a table which has no text columns.

BTW, you might consider using nvarchar(), particularly if your description is not always a full 40 chars in length.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751043
Oh stupid me.

I've been reading and reading the "text in row" page in the Books Online.

I saw it said ...

"You enable the text in row option for a table by using sp_tableoption. With the text in row option set to ON, Microsoft® SQL Server™ 2000 stores text, ntext, or image strings directly in the data row if:..."

And I STILL went ahead and used nchar as the "text" type!

DOH!

Just re-testing script.

0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751081
Hi.

Changed nchar to ntext and dropped the length part, and all is now working.

But BillAn1 raises a good question.

My existing database has text strings upto 255 characters in length and is NOT unicode.

I am converting the app to SQL and making it web based.

The app does need to allow for non ascii letters (european mainly). Do I need national format or not.

And would varchar be better/same as using "text in row" with ntext?

Richard.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751082
Increased points for the additional question.
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 320 total points
ID: 11751140
(var)char is always better for text < 8000 chars. There are a lot of limitations on what you can do with a text datafield. Generally, you should think of it as a 'blob' of data, that you can't parse very well.
regards the languages, depends a bit on what amount of flexibility you want. the standard Latin colation does have most of the normally used characters in european languages, but unicode is more 'robust', and more flexible, so you might be safer to use nvarchar rather than varchar.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751163
Thanks for that.
I've dropped the "text in row" and moved to nvarchar().

Thanks.

Richard Quadling.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question