What is the best data type to store list of email Ids in database? - sql

My requirement is to store a list of emailIds in a single column, What would be the best data type to do so? My columns are like EmailTo , EmailCC, EmailBCC in which I would require storing the list of Ids. Also , help me with the size of the datatype.
I am using SQL server.

It's good to go with NVARCHAR(320) - 64 characters for local part + # + 255 for domain name.
You can refer this for more information.

For email , please use data type as VARCHAR[(n)]
According to defination in MSSQL Server 2008
VARCHAR[(n)] : Describes a variable-length string of single- byte characters.In contrast to the CHAR data type, the values for the VARCHAR data type are stored in their actual length. This data type has two synonyms: CHAR VARYING and CHARACTER VARYING
In building database , I used VARCHAR(45) ,this was working fine for email purposes.

The best data type to store a list (any kind of a list, not just e-mail IDs) is a table. Simple table.
For example, if it is a list of integers, the table would have an int column.
This is what RDBMS is for - they are designed to store data in a bunch of tables.
In your case you'd have several tables: EmailsTo, EmailsCC, EmailsBCC. The structure of your tables would depend on what your EmailID is, what type it is and what other related information (columns) you may need.

Seems Datatype Issue to me.To answer your question ,in my view VARCHAR(MAX) is the highest that can store up-to 8k characters or may be even more if you cast it, but that would not be the correct approach to do.
What you can do is to create a COMMON GROUP and enlist all the email id's to whom you want to send emails. This wont even occupy much of your Datatype space and all peoples can be included within that group as per your comments since you told you require it for sending emails to people.

Related

Storing numbers in character type columns

I'm researching the data types of the field of SAP's data table.
I realized that the fields that only store numbers are sometimes varchar or char data types. e.g., KUNNR(Customer Number) and BUKRS(Company Code) are character data types.
What is the objective or benefit of defining the data type of the fields to varchar/char instead of int when determining the field's data type that only contains numbers by its name's definition?
edit: SAP has "numc" data type and for numeric text and "INT1/2/4/8" data type for interger but use char/varchar for Customer Number or Company Code instead. Please help me if you have the idea why they use char data type for the above cases. I'm now trying to create data schema by referencing SAP's data schema.
Pages that referencing details of SAP's table/fields:
http://www.saptables.net/
https://sapstack.com/
Companies in global supply chain exchanges their transaction data through Electronic Data Interchange(EDI). The data is often variable-length XML or something similar. SAP mainly uses varchar to efficiently use the data for their application. The XML message data for transaction vary from business to business; sometimes number sometimes charcter but required to handle and save to it the database.

Sql Table data type for email address?

What data type should I use for an email? Just started to learn SQL, and I tried to make some columns, here's table for ID, Username, Password, Money, and Email.
Did I make that correctly?
It's good to go with NVARCHAR(320) - 64 characters for local part + # + 255 for domain name.
You Use varchar(255) and nvarchar(255) Data type
Since the max lenght for a email is 254 characters, i would recommend you to use nvarchar(255). That should be enough
you can use varchar as your data type for email column as emails are usually composed of letters, numbers and special characters.
The right value of data lenght for the email field is database-agnostic. If you are also considering standard SQL types, the same can be said for data type, that is a string.
You can take a look at this.

sql server data length [duplicate]

What is the best way to store a large amount of text in a table in SQL server?
Is varchar(max) reliable?
In SQL 2005 and higher, VARCHAR(MAX) is indeed the preferred method. The TEXT type is still available, but primarily for backward compatibility with SQL 2000 and lower.
I like using VARCHAR(MAX) (or actually NVARCHAR) because it works like a standard VARCHAR field. Since it's introduction, I use it rather than TEXT fields whenever possible.
Varchar(max) is available only in SQL 2005 or later. This will store up to 2GB and can be treated as a regular varchar. Before SQL 2005, use the "text" type.
According to the text found here, varbinary(max) is the way to go. You'll be able to store approximately 2GB of data.
Split the text into chunks that your database can actually handle. And, put the split up text in another table. Use the id from the text_chunk table as text_chunk_id in your original table. You might want another column in your table to keep text that fits within your largest text data type.
CREATE TABLE text_chunk (
id NUMBER,
chunk_sequence NUMBER,
text BIGTEXT)
In a BLOB
BLOBs are very large variable binary or character data, typically documents (.txt, .doc) and pictures (.jpeg, .gif, .bmp), which can be stored in a database. In SQL Server, BLOBs can be text, ntext, or image data type, you can use the text type
text
Variable-length non-Unicode data, stored in the code page of the server, with a maximum length of 231 - 1 (2,147,483,647) characters.
Depending on your situation, a design alternative to consider is saving them as .txt file to server and save the file path to your database.
Use nvarchar(max) to store the whole chat conversation thread in a single record. Each individual text message (or block) is identified in the content text by inserting markers.
Example:
{{UserId: Date and time}}<Chat Text>.
On display time UI should be intelligent enough to understand this markers and display it correctly. This way one record should suffice for a single conversation as long as size limit is not reached.

Store both Image and Text in single column in SQL Server

I'm suppose to create reference table, to store key value pair.
Id
Key
Value
Thing is, i need to store both text and image as values, which kind of datatype should be better for this. most case ppl refer Varbinary. but i need to know which one was the best.
Thank You!
What if just store them as separate fields columns?
Id bigint, Key varchar(50), ValueBlob varbinary(max),ValueString varchar(max)
You have to use varbinary(max) unless you encode the image to, say, base 64
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format
If you can't/won't, you'll need to CONVERT the text data into varbinary(max)
That answers your actual question, but does not solve your problem
How will you know what type is stored in the column?
You'll need an extra column to store "type"
Do you intend to search/export the text stored in varbinary in the database?A lot of extra work
A key-value table structure suggests an EAV design which brings a lot of other problems.
Correct solutions:
separate tables for each type of data
separate varchar and varbinary columns

SQL Server : whitespaces in rows

I have this problem where in my database I get lots of empty spaces after my text,
In my email I have "something#mail.com+_________________________________________" lots of spaces
My email row is nchar(255)
and that is happening to all of my tables
Can anyone explain to me why is this happening and how to fix it?
CHAR and NCHAR will automatically right-pad a string with spaces to meet the defined length. Use NVARCHAR(255) instead of NCHAR(255).
you should use nvarchar
SQL Server provides both datatypes to store character information. For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables. Other languages have an extended set of character codes that need to be saved and this datatype allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages from