1

So I just started sql. There is int for integers, character for character string and varchar for either integer or character. Is there a datatype using which I can input both the types together( e.g., A10) ? If not is there an alternative way of doing so?

4
  • 4
    Why is varchar not appropriate for A10? Commented Sep 2, 2015 at 9:09
  • 3
    You answered your question in your question. Commented Sep 2, 2015 at 9:10
  • You can't store A10 in an integer (or even decimal) column. So you do not have the choice in the first place. (Plus you should always mention the DBMS you are using. "SQL" is just a query language, not a DBMS product) Commented Sep 2, 2015 at 9:24
  • Varchar and char are pretty much the same, just a length / padding difference. (Varchar is more like C char type, while char is Cobol/fortran style.) Never store numeric (float, int, decimal etc) data in char/varchar. A10 is not a numeric value, its a string value. Commented Sep 2, 2015 at 9:38

2 Answers 2

1

You said "varchar for either integer or character." Note that the data can be either integer or character or alphanumerics (A10 in your example). This is why VARCHAR is in all DBMSs. It is the datatype you need to use

Sign up to request clarification or add additional context in comments.

Comments

1

You can use CHAR , VARCHAR , VARCHAR 2 , NVARCHAR as datatype for your field(in MsSQL). They all have some different properties but they all store alphanumeric values(i.e A10).

the difference between these datatypes are well explained in the below article:
http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.