Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Thursday, May 2, 2019

Finding a table based on the table name in MSSQL

Here a code I googled on how you can find a table based on its name.

create table #t (
    DBName sysname not null
)
go
exec sp_MSforeachdb 'use [?]; if OBJECT_ID(''dbo.mytable'') is not null insert into #t (DBName) select ''?'''
go
select * from #t
go
drop table #t

Sunday, July 12, 2015

query not execute when click F5

This morning i was hit into a trouble where whenever i click f5 or execute in the sql management studio, it keep prompt the 'save changes' box. I am so confused. Luckily able to figure out that it is because I accidentally clicked on the 'Result to Files'. By selecting the 'Result to Grids', it solved.
:)

Hope this post can save some ppl or myself in future..hehe..

If you not sure where is it, just make sure u select the one circled out with white pen will do.


Monday, January 12, 2015

5 types of system database in SQL

5 types of system database in SQL:
1) Master database
2) Resource database
3) Tempdb database
4) Model database
5) msdb database

1) Master database
- The ''VID''(very important database) of the SQL. Without this database, the server cannot be started. (because it store the initializing information)
- Act as a identity card for the server, because it store all the system level information.
(store all the authorized user information, logon accounts, system configuration settings and others metadata)
- The system object used to store in this master database but it is now in the resource database.
- Physical file : master.ldf and master.mdf
- It is not advise to : change any logon information or change information in the master database. In fact, a lot of changing, dropping, renaming, creating action is not allowed in this database. ( as per mention in msdn.
- If you have to do something with the master database, such as create user object , you are advice to backup the master database. In case of the master database unusable, you can restore the master database or rebuild the master (this is for severe damage, server not able to restart , and this will cause all the system database being rebuild ) .

Friday, June 24, 2011

something i did to show my love towards SQL..^^

those are useful sql statements that are commonly used..

COMMIT;


SELECT * FROM TAB;


DESC TABLENAME;


SET LINESIZE 1000
SET PAGESIZE 1000
/
SELECT * FROM TABLENAME ORDER BY COLUMNNAME ASC;

CREATE VIEW VIEWNAME ( VIEWCOLUMN) AS
SELECT TABLECOLUMN FROM TABLE
WHERE TABLECOLUMN LIKE "%S" /*/*/ "_A%" /*/*/ IS NULL /*/*/ IS NOT NULL /*/*/ = 'STRING'
GROUP BY TABLECOLUMN;