Jump to content

Ms Sql Server Technology Discussions


9Pardhu

Recommended Posts

[quote name='chelsea' timestamp='1349981996' post='1302611988']
[color=#282828][font=helvetica, arial, sans-serif]BEGIN Try[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]TRUNCATE Table dbo.A1[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]TRUNCATE Table dbo.A2[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]TRUNCATE Table dbo.A3[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]TRUNCATE Table dbo.A4[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]TRUNCATE Table dbo.A5[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]Begin end[/font][/color]



BEGIN CATCH

DECLARE @ErrorMessage NVARCHAR(4000) =

'Error Line = ' + ' ' + CAST(ERROR_LINE() AS VARCHAR(10)) + ' ' +
ERROR_MESSAGE()


END CATCH
END

Try cheyyi ba okka sari
[/quote]

SQL Server 2000 doesn't support TRY CATCH. It was introduced in 2005. I've tried this already..Anyways thankyou
[quote name='chelsea' timestamp='1349982160' post='1302612012']


nuvu sql server 2000 antunnavu kada [url="http://www.aspfree.com/c/a/ms-sql-server/exception-handling-in-sql-server-2000-and-2005/"]http://www.aspfree.c...-2000-and-2005/[/url]
[/quote]

indulo single quries ke undi kadaa..what if there are multiple queries like I mentioned above? Does including all of them at a time in a TRANSACTION does it?

Link to comment
Share on other sites

This script lists the name of the foreign key, table name, column name, referenced table name and referenced column name.


;With CTE As
(Select    Object_Name(constraint_object_id) Constraint_Name,
        Object_Name(parent_object_id) Table_Name,
        C.name Column_Name
From sys.foreign_key_columns FK
        Inner Join sys.columns C
            On FK.parent_object_id = C.object_id
            And FK.parent_column_id = C.column_id)
Select    C.Constraint_Name,
        C.Table_Name,
        C.Column_Name,
        Object_Name(FK.referenced_object_id) Referenced_Table_Name,
        SC.name Referenced_Column_Name
from CTE C
    Inner Join sys.foreign_key_columns FK
        On C.Constraint_Name = Object_Name(FK.constraint_object_id)
    Inner Join sys.columns SC
        On FK.referenced_object_id = SC.object_id
    And FK.referenced_column_id = SC.column_id



idi chala basic ga adige question chala mandi..anduke post chestunna..evarikaina use avutundemo ani S@nC#aZi

Link to comment
Share on other sites

[quote name='deals2buy' timestamp='1350066568' post='1302618753']
akkada post chesanu chudu..btw nuvvu DBA ve kada..neeku teleeda? :P
[/quote]

anni solutions ikkada vuntai ani vesa...
peru key DBA

Link to comment
Share on other sites

[quote name='9pardhu' timestamp='1350069942' post='1302619331']

anni solutions ikkada vuntai ani vesa...
peru key DBA
[/quote]
aithe akkada nenu post chesindi teesukochi ikkada vey nuvvu @3$%

peru ke DBA antunnav? @3$% em pani sestav akkada ? @3$%

Link to comment
Share on other sites

[quote name='deals2buy' timestamp='1350070192' post='1302619362']
aithe akkada nenu post chesindi teesukochi ikkada vey nuvvu @3$%

peru ke DBA antunnav? @3$% em pani sestav akkada ? @3$%
[/quote]

[img]http://www.desigifs.com/sites/default/files/133797509956213.gif?1337975770[/img]

edo bhayya memu ee field lo edugutunam.. appude tokkestara

Link to comment
Share on other sites

[quote name='9pardhu' timestamp='1350259500' post='1302629563']

[img]http://www.desigifs.com/sites/default/files/133797509956213.gif?1337975770[/img]

edo bhayya memu ee field lo edugutunam.. appude tokkestara
[/quote]


naakante senior vi...nuvve ala ante ela? @3$%

Link to comment
Share on other sites

[b] Create A Folder With T-SQL[/b]


This is a very simple stored procedure, which basically takes a folder name as input, checks to see if the folder exists and if it doesn't it creates it using xp_create_subdir.
Before running, it checks to ensure that the drive specified (the first character of the input string) is valid on the system you are running it on.

/***************************************************************************
*** ***
*** Title : usp__CreateDirectory                     ***
*** Description : Pass a path to the SP and it will create the         ***
*** the relevant folder for you.                     ***
***                                     ***
***************************************************************************/

CREATE PROCEDURE usp__CreateDirectory
@NewFolder    varchar(500)
AS

SET NOCOUNT ON
-- Create a table variable to hold the results of xp_fileexist --
DECLARE @DoesFolderExist
TABLE
(
FileExists int NOT NULL,
FileIsDirectory int NOT NULL,
ParentDirExists int NOT NULL
)
-- Create a table variable to hold the results of xp_fixeddrives --
DECLARE @Drives
TABLE
(
Drive char(1) NOT NULL,
FreeSpace int    NOT NULL
)
-- Grab a list of available drives and inse them into the @Drives table vairable --
INSERT INTO @Drives
EXEC master.dbo.xp_fixeddrives
-- Does the drive exist, if not - stop here --
IF LEFT(@NewFolder, 1) NOT IN (SELECT Drive FROM @Drives)
BEGIN
PRINT 'That drive does not exist'
RETURN
END
-- Check to see if the folder already exists, if not, create it --
INSERT INTO @DoesFolderExist
EXEC master.dbo.xp_fileexist @NewFolder
IF (SELECT FileIsDirectory FROM @DoesFolderExist) = 0
BEGIN
EXECUTE master.dbo.xp_create_subdir @NewFolder
PRINT 'Directory Created'
END
ELSE
PRINT 'Directory Already Exists'
SET NOCOUNT OFF




idi chala cases lo use chestam SQL Server lo...SSIS unnavaallu mostly tool use chesi chestuntaru idi...

T-SQL is the heart for everything kabatti, adi use chesi ela cheyyalo ikkada posting

Hope it helps for someone

Link to comment
Share on other sites

[quote name='deals2buy' timestamp='1350396313' post='1302635927']
[b] Create A Folder With T-SQL[/b]


This is a very simple stored procedure, which basically takes a folder name as input, checks to see if the folder exists and if it doesn't it creates it using xp_create_subdir.
Before running, it checks to ensure that the drive specified (the first character of the input string) is valid on the system you are running it on.

/***************************************************************************
*** ***
*** Title : usp__CreateDirectory                     ***
*** Description : Pass a path to the SP and it will create the         ***
*** the relevant folder for you.                     ***
***                                     ***
***************************************************************************/

CREATE PROCEDURE usp__CreateDirectory
@NewFolder    varchar(500)
AS

SET NOCOUNT ON
-- Create a table variable to hold the results of xp_fileexist --
DECLARE @DoesFolderExist
TABLE
(
FileExists int NOT NULL,
FileIsDirectory int NOT NULL,
ParentDirExists int NOT NULL
)
-- Create a table variable to hold the results of xp_fixeddrives --
DECLARE @Drives
TABLE
(
Drive char(1) NOT NULL,
FreeSpace int    NOT NULL
)
-- Grab a list of available drives and inse them into the @Drives table vairable --
INSERT INTO @Drives
EXEC master.dbo.xp_fixeddrives
-- Does the drive exist, if not - stop here --
IF LEFT(@NewFolder, 1) NOT IN (SELECT Drive FROM @Drives)
BEGIN
PRINT 'That drive does not exist'
RETURN
END
-- Check to see if the folder already exists, if not, create it --
INSERT INTO @DoesFolderExist
EXEC master.dbo.xp_fileexist @NewFolder
IF (SELECT FileIsDirectory FROM @DoesFolderExist) = 0
BEGIN
EXECUTE master.dbo.xp_create_subdir @NewFolder
PRINT 'Directory Created'
END
ELSE
PRINT 'Directory Already Exists'
SET NOCOUNT OFF




idi chala cases lo use chestam SQL Server lo...SSIS unnavaallu mostly tool use chesi chestuntaru idi...

T-SQL is the heart for everything kabatti, adi use chesi ela cheyyalo ikkada posting

Hope it helps for someone
[/quote]


Good Post

Link to comment
Share on other sites

Oracle lo MINUS ani oka option untundi. To check what are the columns that are in one table and not it other table which are almost identical.

Similar ga SQL Server lo kuda undo ledo ani eppati nundo trying...this is the code for such thing..

Might be helpful to someone


[color="#0000ff"]USE[/color][color="#000000"] TempDB[/color]
GO
[color="#0000ff"]CREATE[/color] [color="#0000ff"]TABLE[/color][color="#000000"] ArchiveTable [/color][color="#808080"]([/color][color="#000000"]ID [/color][color="#0000ff"]INT[/color][color="#808080"],[/color][color="#000000"] Col1 VARCHAR[/color][color="#808080"]([/color][color="#000000"]10[/color][color="#808080"]),[/color][color="#000000"] Col2 VARCHAR[/color][color="#808080"]([/color][color="#000000"]100[/color][color="#808080"]),[/color][color="#000000"] Col3 VARCHAR[/color][color="#808080"]([/color][color="#000000"]100[/color][color="#808080"]));[/color]
[color="#0000ff"]CREATE[/color] [color="#0000ff"]TABLE[/color][color="#000000"] CurrentTable [/color][color="#808080"]([/color][color="#000000"]ID [/color][color="#0000ff"]INT[/color][color="#808080"],[/color][color="#000000"] Col1 VARCHAR[/color][color="#808080"]([/color][color="#000000"]10[/color][color="#808080"]),[/color][color="#000000"] Col2 VARCHAR[/color][color="#808080"]([/color][color="#000000"]100[/color][color="#808080"]),[/color][color="#000000"] Col3 VARCHAR[/color][color="#808080"]([/color][color="#000000"]100[/color][color="#808080"]),[/color][color="#000000"] ExtraCol [/color][color="#0000ff"]INT[/color][color="#808080"]);[/color]
GO
[color="#008000"]-- Columns in ArchiveTable but not in CurrentTable[/color]
[color="#0000ff"]SELECT[/color][color="#000000"] name ColumnName[/color]
[color="#0000ff"]FROM[/color][color="#000000"] sys[/color][color="#808080"].[/color][color="#000000"]columns[/color]
[color="#0000ff"]WHERE[/color] [color="#ff00ff"]OBJECT_NAME[/color][color="#808080"]([/color][color="#ff00ff"]OBJECT_ID[/color][color="#808080"])[/color] [color="#808080"]=[/color] [color="#ff0000"]'ArchiveTable'[/color]
[color="#0000ff"]EXCEPT[/color]
[color="#0000ff"]SELECT[/color][color="#000000"] name ColumnName[/color]
[color="#0000ff"]FROM[/color][color="#000000"] sys[/color][color="#808080"].[/color][color="#000000"]columns[/color]
[color="#0000ff"]WHERE[/color] [color="#ff00ff"]OBJECT_NAME[/color][color="#808080"]([/color][color="#ff00ff"]OBJECT_ID[/color][color="#808080"])[/color] [color="#808080"]=[/color] [color="#ff0000"]'CurrentTable'[/color]
GO
[color="#008000"]-- Columns in CurrentTable but not in ArchiveTable[/color]
[color="#0000ff"]SELECT[/color][color="#000000"] name ColumnName[/color]
[color="#0000ff"]FROM[/color][color="#000000"] sys[/color][color="#808080"].[/color][color="#000000"]columns[/color]
[color="#0000ff"]WHERE[/color] [color="#ff00ff"]OBJECT_NAME[/color][color="#808080"]([/color][color="#ff00ff"]OBJECT_ID[/color][color="#808080"])[/color] [color="#808080"]=[/color] [color="#ff0000"]'CurrentTable'[/color]
[color="#0000ff"]EXCEPT[/color]
[color="#0000ff"]SELECT[/color][color="#000000"] name ColumnName[/color]
[color="#0000ff"]FROM[/color][color="#000000"] sys[/color][color="#808080"].[/color][color="#000000"]columns[/color]
[color="#0000ff"]WHERE[/color] [color="#ff00ff"]OBJECT_NAME[/color][color="#808080"]([/color][color="#ff00ff"]OBJECT_ID[/color][color="#808080"])[/color] [color="#808080"]=[/color] [color="#ff0000"]'ArchiveTable'[/color]
GO
[color="#0000ff"]DROP[/color] [color="#0000ff"]TABLE[/color][color="#000000"] ArchiveTable[/color][color="#808080"];[/color]
[color="#0000ff"]DROP[/color] [color="#0000ff"]TABLE[/color][color="#000000"] CurrentTable[/color][color="#808080"];[/color]
GO

Link to comment
Share on other sites

ikkada saana mandi Developers kante DBAs ekkuva unnaru la undi

vaalla kosam....idi saana useful info vaa

Check out

[url="http://www.sqlservercentral.com/articles/CPU/71388/"]http://www.sqlservercentral.com/articles/CPU/71388/[/url]

Link to comment
Share on other sites

Guys, Sacremento lo na friend okadu company nunchi going out vadiki replacement ki vethukuthunaru , any sql guy with 2 yrs real exp untey chepandi .. resume pampistha ! pay thakuva untadi vendor ki 65 ala vasthadi!

Link to comment
Share on other sites

[quote name='JUJUBI_JULABI' timestamp='1350657862' post='1302655878']
Guys, Sacremento lo na friend okadu company nunchi going out vadiki replacement ki vethukuthunaru , any sql guy with 2 yrs real exp untey chepandi .. resume pampistha ! pay thakuva untadi vendor ki 65 ala vasthadi!
[/quote]


requirements emaina unte kanuka aa details anni kalipi ee kinda thread lo post chey mama..

evaraikaina use avvochu

[url="http://www.andhrafriends.com/topic/343901-monna-evaro-sql-server-position-adigaaru-kada-db-lo/"]http://www.andhrafriends.com/topic/343901-monna-evaro-sql-server-position-adigaaru-kada-db-lo/[/url]

Link to comment
Share on other sites

saradaga ee query try cheyyandi vaa SQL Server vaallu @3$%


[color="#0000ff"]SELECT[/color] [color="#ff00ff"]STR[/color][color="#808080"]([/color][color="#000000"]987.65[/color][color="#808080"],[/color][color="#000000"] 2[/color][color="#808080"],[/color][color="#000000"] 3[/color][color="#808080"]);[/color]
GO

Link to comment
Share on other sites

×
×
  • Create New...