sql server stored procedure
CREATE PROCEDURE spGetEmployeeCountByGender
@Gender nvarchar(20),
@EmployeeCount int Output
AS
BEGIN
SELECT @EmployeeCount = COUNT(Id)
FROM tblEmployee
WHERE Gender = @Gender
END
sql server stored procedure
CREATE PROCEDURE spGetEmployeeCountByGender
@Gender nvarchar(20),
@EmployeeCount int Output
AS
BEGIN
SELECT @EmployeeCount = COUNT(Id)
FROM tblEmployee
WHERE Gender = @Gender
END
create select stored procedure in sql server
CREATE PROCEDURE sp_getRaces
AS
BEGIN
SELECT * FROM dbo.Races
END ;
Explain the Stored Procedure
Stored Procedure :
A stored procedure is a prepared SQL code that you can save,
so the code can be reused over and over again.
So if you have an SQL query that you write over and over again,
save it as a stored procedure, and then just call it to execute it.
You can also pass parameters to a stored procedure,
so that the stored procedure can act based on the parameter value(s)
that is passed.
procedure in sql
-Stored procedure is a group of SQL
statements that has been created
and stored in the database.
-A stored procedure will accept input
parameters so that a single procedure
can be used over the network by several
clients using different input data.
-A stored procedures will reduce
network traffic and increase the performance.
If we modify a stored procedure all the
clients will get the updated stored procedure.
Sample of creating a stored procedure
CREATE PROCEDURE test_display AS
SELECT FirstName, LastName FROM tb_test
EXEC test_display
Stored-Procedure
@EnableJpaRepositories
@ComponentScan
@Configuration
public class AppConfig {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.HSQL)
.addScript("create-tables.sql")
.addScript("procedure.sql")
.setSeparator("/;")
.build();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory =
new LocalContainerEntityManagerFactoryBean();
factory.setPersistenceProviderClass(HibernatePersistenceProvider.class);
factory.setDataSource(dataSource());
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "update");
factory.setJpaProperties(properties);
return factory;
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory().getObject());
return txManager;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us