mengambil hasil prosedur tersimpan sistem

Sekitar satu jam saya berkutat untuk mencari bagaimana cara mengambil hasil dari prosedur tersimpan sistem (system stored procedure) SQL Server (spesifiknya sp_tables_ex) untuk dapat dimanipulasi lebih lanjut. Fiuh, akhirnya ketemu juga solusinya di codecomments. Ternyata hasilnya dapat dimasukkan ke dalam tabel dengan sintaks INSERT INTO ... EXEC stored_procedure ...

create table #cmfGL (
	TABLE_CAT varchar(50), TABLE_SCHEM varchar(50),
	TABLE_NAME varchar(50), TABLE_TYPE varchar(50),
	REMARKS varchar(50)
)
insert into #cmfGL
	exec sp_tables_ex @table_server='cmfGL'
select TABLE_NAME from #cmfGL
drop table #cmfGL

tips optimisasi sql server

Dari MS SQL City, ada beberapa tips menarik (sebagian belum diterjemahkan) mengenai optimisasi sql server.

  1. Gunakan SP sebagai alternatif kueri yang berat.
  2. Gunakan SET NOCOUNT ON untuk menghindari munculnya pesan jumlah data yang terpengaruh.
  3. Gunakan nama terkualifikasi lengkapnya: server.db.owner.object untuk memberikan kesempatan server menggunakan ulang rencana eksekusinya.
  4. Gunakan nilai keluaran integer untuk apapun untuk menghindari pembuatan recordset.
  5. Don’t use the prefix “sp_” in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.
  6. Use the sp_executesql stored procedure instead of the EXECUTE statement.
  7. Use sp_executesql stored procedure instead of temporary stored procedures.
  8. If you have a very large stored procedure, try to break down this stored procedure into several sub-procedures, and call them from a controlling stored procedure.
  9. Try to avoid using temporary tables inside your stored procedure.
  10. Try to avoid using DDL (Data Definition Language) statements inside your stored procedure.
  11. Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.
  12. Use SQL Server Profiler to determine which stored procedures has been recompiled too often.