SQL little table allocated in memory

2019-08-29 06:30发布

问题:

Is there a way to make SQL Server to store a table with 10 attributes and 10 rows like this on memory?

a1   a2   a3  a4  a5  a6  a7  a8  a9 a10
----------------------------------------
138 498  365 345 500 473 498 125 134 800
448 498  362 348 500 463 498 625 165 700
468 498  625 329 500 435 498 625 345 600
437 701  365 326 500 453 498 625 645 500
438 498  326 329 500 438 498 625 745 400
439 499  626 329 500 438 498 525 685 300
440 500  327 328 500 423 498 627 655 200
444 214  331 334 500 428 498 125 615 100
448 498  362 348 500 463 498 225 165 700
468 498  625 329 500 435 498 425 345 600

Is there a way to store this table in contiguous memory?

I was thinking to make somekind of vector and make the table a single row (instead of 10 attributes by 10 rows make a vector with size 100. Is there a way to do this?

You may ask why I want to do this, It is because I would like to make some calculus all in memory avoiding writing or using disk, and then access the memory or vector in C++ or .NET (maybe C#?)

回答1:

Don't try to dictate to SQL Server how to handle memory for things like this. It's a declarative language - you tell it what you want and it figures out how to do it.

Keeping it in memory only would be an issue for recovery. That being said, once you create the table it will be kept in memory once it's written to disk. SQL Server caches data pages, and something like this would be a single page so a lot of disk access shouldn't be a problem.



回答2:

Recently, Microsoft provides SQL Server 2012 with in-memory databases. It is very good news for project who requires a high performance database.