Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

String

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
bufordk
Asked:
bufordk
  • 4
  • 2
1 Solution
 
odessaCommented:
String is not a data type or System word, it only describe String as String
0
 
mayhewCommented:
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
 
bufordkAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mayhewCommented:
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
 
mayhewCommented:
Sorry, I meant to say you would have a datatype named longstring, not a column.
0
 
bufordkAuthor Commented:
thank you for your clear and understandable answer.
0
 
mayhewCommented:
Glad I could help!   :)
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.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now