< Back

Invoke-SdfCmd

Sat Jan 11, 2020 8:31 am

NAME Invoke-SdfCmd



SYNOPSIS

Executes a T-SQL command against a SQL Server CE file





SYNTAX

Invoke-SdfCmd -TQuery <String> [<CommonParameters>]



Invoke-SdfCmd [-ReplaceVariables <String[]>] -Query <String> [<CommonParameters>]





DESCRIPTION

Run a T-SQL query against a SQL SErver CE database (.sdf file)





PARAMETERS

-TQuery <String>

Any TSQL query that is allowed in SQL Server CE



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ReplaceVariables <String[]>

A string collection for updating a saved query. Format string is used in the function, thus elements 0,1,2,3

... are replaced with the equivalent {0}, {1}, {2} in the saved Query according to the string replace rules.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Query <String>

Saved TSQL queries. Autocomplete is enabled on saved Queries. Additional saved queries can be added by running

Set-SavedQuery



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

None







OUTPUTS

System.Object







NOTES









-------------------------- Example 1 --------------------------



PS C:\\> Connect-SdfFile c:\\Temp\\MyDatabase.sdf

PS C:\\> Invoke-SdfCmd -TQuery "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'"



Lists all tables in the MyDatabase SQL Server CE database

-------------------------- Example 2 --------------------------



PS C:\\> Invoke-SdfCmd -TQuery "CREATE TABLE [MyTable] ([Id] int NOT NULL IDENTITY (1,1), [Name] nvarchar(450) NOT

NULL);"

PS C:\\> Invoke-SdfCmd -TQuery "ALTER TABLE [MyTable] ADD CONSTRAINT [PK_MyTable] PRIMARY KEY ([Id]);"

PS C:\\> Invoke-SdfCmd -TQuery "ALTER TABLE [MyTable] ADD CONSTRAINT [PK_MyTable] PRIMARY KEY ([Id]);"

PS C:\\> Invoke-SdfCmd -TQuery "CREATE UNIQUE INDEX [IX_MyTable_Name] ON [MyTable] ([Name] ASC);"



Creates a new table in the databse currently bound by Connect-SdfFile

-------------------------- Example 3 --------------------------



PS C:\\> Invoke-SdfCmd -TQuery "SELECT * from MyTable"



Retrieves all lines in MyTable



RELATED LINKS