How do I generate CRUD stored procedures from a table in SQL Server Management Studio

后端 未结 8 973
攒了一身酷
攒了一身酷 2020-12-15 07:57

How do I take a table, and auto-gen CRUD stored procs for it in SSMS?

相关标签:
8条回答
  • 2020-12-15 08:52

    Beside tools mentioned before, there is another free tool you can use to get the job done in a few clicks.

    To do so, you need to enter prefix and suffix in the ApexSQL Complete options window, where you can choose one of the sub-tabs for each of CRUD procedure templates (Select, Insert, Update, Delete). After this is done, the CRUD procedures feature will be available by right clicking in the Object Explorer window, in database or table in the drop down menu.

    Here is an article with more details about this functionality (article is a bit old though, as feature is added into the current release)

    0 讨论(0)
  • 2020-12-15 08:55
    CREATE PROCEDURE SP_USUARIO
    @usuario varchar(30)=null,
    @clave varchar(500)=null,
    @idPersona int=null,
    @idRol int=null,
    @idUsuario int=null,
    @TIPO TINYINT=1
    AS
    BEGIN
        IF @TIPO=1 -- LISTAR PERSONAS
        BEGIN
            SELECT idPersona,Nombre,ApePaterno,ApeMaterno,DNI,Direccion,celular,email FROM Persona
        END
        IF @TIPO=2 -- LISTAR ROLES
        BEGIN
            SELECT idRol,Nombre,Descripcion FROM ROL
        END
        IF @TIPO=3 -- LISTAR USUARIOS
        BEGIN
            SELECT idUsuario,usuario,pass,idPersona,idRol from Usuario
        END
        IF @TIPO=3 -- USUARIOS
        BEGIN
            SELECT idUsuario,usuario,pass,idPersona,idRol from Usuario where idUsuario=@idUsuario
        END
        IF @TIPO=4 -- AGREGAR USUARIO
        BEGIN
            INSERT Usuario(usuario,pass,idPersona,idRol) values(@usuario,@clave,@idPersona,@idRol)
        END
        IF @TIPO=5 -- EDITAR USUARIO
        BEGIN
            UPDATE Usuario SET usuario=@usuario,pass=@clave,@idPersona=@idPersona,idRol=@idRol where idUsuario=@idUsuario
        END
        IF @TIPO=6 -- ELIMINAR USUARIO
        BEGIN
            DELETE Usuario WHERE idUsuario=@idUsuario
        END
    END
    
    go
    
    0 讨论(0)
提交回复
热议问题