0
votes

I was wondering if it was possible preserve name of the table that I import into Azure Table Storage? And is it possible to import multiple databases of the same column structure into Azure Table Storage?

I'm asking this before I buy Azure Table Storage I just want to make sure it works for whatever I need to do.

Update: So I have a database with around 500 tables and they all have the relatively same columns Username, Email, Hash, Salt, Name, IP etc... some some tables only have username and email while others have more or less. However, in the end all the tables have the exact same spelling for columns. I want to create a Azure Table Storage with all the columns. Then import all the tables. SO tables lacking columns will just have null in the columns they don't have. But I want to import the table name into a column. So if table1 is imported one column will be named "Database Name" and table1's name will be in it and so on.

Update 2: So is it possible to do something like this. As seen here in

 CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
 customer1.Email = "[email protected]";
 customer1.PhoneNumber = "425-555-0101";

I would want to have

WebsiteEntity website1 = new WebsiteEntity("Google");
website1.Username = "username1"
website1.email = "[email protected]"

I guess what i'm saying is it possible to put the table name that I import into the WebsiteEntity shown above? And than automatically have it create like .username and .email if it's in the SQL table being imported? Like the column. So table 1 has column username and email and is named Google so when importing websiteentity will be Google and website1.username and website1.email will automatically be created.

Thank you in advanced i'm very new to this.

Update 3: After further research, my question is can I import each table from a MySQL database into its own partition?

2
Can you please describe your scenario in more details. Kindly update your question and provide as much information as possible about what you're trying to do. As it stands now, what you're asking for is not clear.Gaurav Mantri
Table storage doesn't have the notion of columns - just properties for each entity (and no rules of enforcement to ensure each entity has the same properties, aside from application-side rules). Note: Table Storage tables are not the same as, say, SQL Server tables.David Makogon
It's not clear what you want. Table storage doesn't have a schema like SQL tables do, you can add entities with different properties to the same table.gbellmann
so if one entity had username, and email and the second entity had username, email, and password will the password be automatically added with no problem? Also if I import multiple tables into table storage from mysql how will i know which entity is from each table?Alex Rieker

2 Answers

0
votes

Each azure table entity have partition key and row key, an entity's partition and row key uniquely identify the entity in the table. We can use MySQL table name as partition key and use MySQL primary key as row key. So that we can use partition key to know where our entity from.

Such as, if have a table called User in MySQL, then create an entity

public class UserEntity : TableEntity
{
    public UserEntity(string tablename, string primarykey)
    {
        this.PartitionKey = "User";
        this.RowKey = primarykey;
    }

    public UserEntity() { }

    public string UserName { get; set; }

    public string Email { get; set; }
}

And create Person for MySQL person table.

public class PersonEntity : TableEntity
{
    public UserEntity(string tablename, string primarykey)
    {
        this.PartitionKey = "Person";
        this.RowKey = primarykey;
    }

    public PersonEntity() { }

    public string UserName { get; set; }

    public string Email { get; set; }

    public string Password { get; set; }

}

Then we read the data from MySQL. and create entity with the value from MySQL, insert to Azure table. Refer to this article to know how to get started with Azure table.

Here is the result from Azure Storage Explorer. We can know the first entity from "Person" MySQL table and the second entity from "User" MySQL table. This is a simple achievement. If you have some special requirement, please create new Azure table structure.

enter image description here

0
votes

If you want to insert each of the source tables into their own partition in table storage, the only way to do that is to make sure all entities from the source table are written with the same partition key. You also mentioned that you have a requirement to find out which entity belonged to which source table originally, so you do not really have much option but use your source table name as your partition key when writing entities from that table to azure table storage and construct a row key that will allow you to uniquely identify that entity within that partition.

If your source tables have a lot of entities or you expect them to grow more in future this is not a recommended scalable design. You could keep partition keys unique and append or prepend the source table name to the row key with a delimiter for instance as an alternative.

Also just to mention do not try to add the source table name as a property and filter for it later on, this is worst of worst designs :) It will cause a table scan in your entire big azure table.

Next question about missing properties on some entities, Azure table storage is a NoSql db so if you insert an entity with missing properties or properties exist but they have null value (ie. a null string), that entity will be written to azure table storage without that property. From azure table service perspective you are requesting to write a dictionary of key value pairs and that s all, the service does not care or know what constraints or schemas you have on your application/client side.

When you read the entities back you can either read them as DynamicTableEntities or with concrete type using the Storage SDK.