Solved

String

Posted on 1998-09-04
7
228 Views
Last Modified: 2010-03-19
I know this maybe a dumb question but the word 'STRING'confuses me in SQL. What is a 'STRING'in SQL, is it just a word discribing a data type or is it a system word?
0
Comment
Question by:bufordk
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:odessa
Comment Utility
String is not a data type or System word, it only describe String as String
0
 
LVL 5

Accepted Solution

by:
mayhew earned 50 total points
Comment Utility
As Odessa suggested, string is not a datatype.  What it refers to is any character data like data of types char and varchar.  Or a string could be a literal that you use, for example, in a where clause.  Eg.

SELECT * FROM <table> WHERE <name> = 'buford'

The 'buford' could be considered a string.

It also refers to a set of 'string functions'.  These are functions you can use to manipulate data of types char, varchar, binary and varbinary.  I've never personally used these functions for binary data, but I know they will work

An example would be the substring function which (as you may know) finds a sub-string in string str that begins on position m and has a length of n.

SUBSTRING(str,m,n)

str is a string and either of the following function calls would be valid:

SUBSTRING('buford',3,4)
SUBSTRING(<col_name>,3,4)

'buford' and a column from a table of type char (for example) would both be considered strings.

You can also concatenate strings with a '+' sign.  For example:

SELECT <name> + ' is smart' FROM <table>

Hope that's helpful!   :)
0
 

Author Comment

by:bufordk
Comment Utility
Thank You for your helpful answer. Just one more thing to maybe clarify things.
when i execute

sp_addtype zipcode, 'char(10)'  

 vs.
                       
sp_addtype longstring, 'varchar(60)'

is 'longstring' discribing varchar(60) like 'zipcode' discribes char(10) the user datatype?
i understand substrings and etc. but that word '%string' in a user datatype scares me.
Maybe i'm just looking to deep into the word and not seeing a simple answer.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Expert Comment

by:mayhew
Comment Utility
Yes, if you execute

sp_addtype longstring, 'varchar(60)'

you are going to have a column named longstring.  I think I understand your concern.  SQL Server will give you an error if you use any kind of reserved word for a column name.

In SQL Server, the word 'string' is more of a concept than datatype.  You should have no trouble naming anything %string%.

Let me know if you have any further questions.  :)
0
 
LVL 5

Expert Comment

by:mayhew
Comment Utility
Sorry, I meant to say you would have a datatype named longstring, not a column.
0
 

Author Comment

by:bufordk
Comment Utility
thank you for your clear and understandable answer.
0
 
LVL 5

Expert Comment

by:mayhew
Comment Utility
Glad I could help!   :)
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now