0% found this document useful (0 votes)
76 views

SQLNotes

The document describes different data types in SQL Server including integer, numeric, datetime, character, and binary types. It provides the allowed values and precision for each data type. It also includes examples of SQL statements for creating and modifying tables, adding and updating data, renaming columns, and using cursors.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

SQLNotes

The document describes different data types in SQL Server including integer, numeric, datetime, character, and binary types. It provides the allowed values and precision for each data type. It also includes examples of SQL statements for creating and modifying tables, adding and updating data, renaming columns, and using cursors.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Server BIT TINYINT SMALLINT INT BIGINT REAL FLOAT MONEY SMALLMONEY DECIMAL NUMERIC DATETIME CHARn

NCHARn VARCHARn NVARCHARn TEXT NTEXT BINARY VARBINARY IMAGE

Data Precision Integer: 0 or 1 Positive Integer 0 -> 255 Signed Integer -32,768 -> 32,767 Signed Integer -2^31 -> 2^31-1 Signed Integer -2^63 -> 2^63-1 Floating precision -1.79E + 308 -> 1.79E + 308 Floating precision -3.40E + 38 -> 3.40E + 38 4 decimal places, -2^63/10000 -> 2^63-1/10000 4 decimal places, -214,748.3648 -> 214,748.3647 Fixed precision -10^38 + 1 -> 10^38 - 1 Fixed precision -10^38 + 1 -> 10^38 - 1 Date+Time 1753-01-01 -> 9999-12-31, accuracy of 3.33 ms Fixed-length non-Unicode string to 8,000 characters Fixed-length Unicode string to 4,000 characters Variable-length non-Unicode string to 8,000 characters Variable-length Unicode string to 4,000 characters Variable-length non-Unicode string to 2,147,483,647 characters Variable-length Unicode string to 1,073,741,823 characters Fixed-length binary data up to 8,000 characters Variable-length binary data up to 8,000 characters Variable-length binary data up to 2,147,483,647 characters

SMALLDATETIME Date+Time 1900-01-01 -> 2079-06-06, accuracy of one minute

Links de ayuda storeprocedures http://www.sqlinfo.net/sqlserver/sql_server_stored_procedure_SELECT.ph p Crear una tabla


CREATE TABLE address ( person_num INT NOT NULL , type_code CHAR(4) NOT NULL , street1 CHAR(30) NULL , street2 CHAR(30) NULL , city CHAR(30) NULL , state CHAR(2) NULL , postal_code CHAR(10) NULL , CONSTRAINT PK_address PRIMARY KEY CLUSTERED (person_num ASC, type_code ASC) ON [PRIMARY] ) GO

Agregar una columna

Alter table Gen_Maquinas Add [codRecibidero] [smallint] NULL

GO Alterar una columna existente ALTER TABLE [dbo].[person] ALTER COLUMN [lastname] VARCHAR(35) NULL GO

Update Set
UPDATE <nombre_tabla> SET <campo1> = <valor1> {[,<campo2> = <valor2>,...,<campoN> = <valorN>]}[ WHERE <condicion>];

Agregar datos a columnas especificndoles un parametro


update Gen_Maquinas set codRecibidero=1 where codEmpresa=1

Agregar datos a columnas haciendo una sub consulta


UPDATE tCochesSET marca = (SELECT CODIGO FROM tMarcas WHERE tMarcas.Marca = tCoches.Marca ) WHERE marca IN ('FORD','RENAULT','SEAT');

Cambiar nombre de column


EXEC sp_rename 'Gen_Maquinas.Prueba', 'Detalle' , 'COLUMN' Go Tambien se puede utilizar SP_RENAME 'Gen_Maquinas.desMaquina', 'Detalle' , 'COLUMN' GO

Buscar el conflicto de las maquinas buscar datos que hagan referencia a las maquinas pero que no esten en la tabla maquinas select * from Ent_entregas where codMaquina not in (select codMaquina from Gen_maquinas) or codMaquina is null editvaluechangebuscar si es nulo COMO CREAR UN CURSOR DECLARE @CD_EMPRESA INT,@CD_DEPTO INT,@DS_DEPTO VARCHAR(100) DECLARE C CURSOR FOR--**** SELECT CD_EMPRESA,CD_DEPTO,DS_DEPTO--CAMPOS DE LAS TALAS DEL JOIN T2.CD_BOLETIN--**** FROM MANT_DEPTOS T1--**** --JOIN WHERE CD_EMPRESA=1--**** open C--**** fetch next from C into @CD_EMPRESA,@CD_DEPTO,@DS_DEPTO--**** while @@fetch_status = 0--**** begin--****

UPDATE MANT_DEPTOS SET CD_CENTRO_COSTO=1 WHERE CD_DEPTO=5 fetch next from C into @CD_EMPRESA,@CD_DEPTO,@DS_DEPTO--**** end--**** close C--**** deallocate C--****

You might also like