SQL

Member

letha

Design Product Table in SQL when you don't know how is foreign keys works in SQL 🤣

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
--
-- Table structure for table `products`
--


CREATE TABLE `products` (
  `product_id` int(100) NOT NULL,
  `product_cat` int(100) NOT NULL,
  `product_brand` int(100) NOT NULL,
  `product_title` varchar(255) NOT NULL,
  `product_price` int(100) NOT NULL,
  `product_desc` text NOT NULL,
  `product_image` text NOT NULL,
  `product_keywords` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Member

adelia_boyer

by adelia_boyer , in category: SQL , 22 days ago
no answers

Convert Current Date to MSSQL format 🤗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
SET @DD = DATEPART(dd, GETDATE())
SET @MM = DATEPART(mm, GETDATE())
SET @YYYY = DATEPART(yyyy, GETDATE())

IF LEN(@DD) = '1'
	BEGIN
		SET @DD = '0' + @DD
	END
IF LEN(@MM) = '1'
	BEGIN
		SET @MM = '0' + @MM
	END

SET @DT_D = @DD + '.' + @MM + '.' + @YYYY


Member

makayla.beahan

by makayla.beahan , in category: SQL , 23 days ago
no answers

The design of menu table in SQL 😝

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
CREATE TABLE IF NOT EXISTS `upmenu_block` (
  `id_foto_b` int(5) NOT NULL auto_increment,
  `id_sec` int(5) NOT NULL,
  `f_b1` varchar(100) NOT NULL,
  `f_b2` varchar(100) NOT NULL,
  `f_b3` varchar(100) NOT NULL,
  `f_b4` varchar(100) NOT NULL,
  `f_o1` varchar(200) NOT NULL,
  `f_o2` varchar(200) NOT NULL,
  `f_o3` varchar(200) NOT NULL,
  `f_o4` varchar(200) NOT NULL
  PRIMARY KEY  (`id_foto_b`)
)


Member

makayla.beahan

Do we really need this SQL ? It's supposed to be always 0 Rows Affected. 🙃

1
UPDATE `options_table` SET `option_value_ru` = 'Оutlet' WHERE `option_value_ru` LIKE 'Outlet'

Member

zora.stokes

by zora.stokes , in category: SQL , a month ago
no answers

Select statement with many null in SQL

1
2
3
4
SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
       type_table_of_name_tag_value ()
  FROM DUAL
 WHERE dummy = 'Z'

Member

lou_lindgren

Design log event table including ALL keys in SQL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CREATE TABLE `log_event` (
  `id` bigint(20) NOT NULL auto_increment,
  `logtime` datetime default NULL,
  `etype` text,
  `module` text,
  `edata` text,
  `session` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
  KEY `id_2` (`id`)
)


Member

zora.stokes

by zora.stokes , in category: SQL , a month ago
no answers

How to round numbers and remove 0 in SQL

1
SELECT REPLACE(RTRIM(REPLACE(REPLACE(RTRIM(REPLACE(LTRIM('  850.0000'),'0',' ')),' ','0'),'.',' ')),' ','.')


Member

zora.stokes

by zora.stokes , in category: SQL , a month ago
no answers

User Administrator relation in SQL

1
2
3
4
CREATE TABLE IF NOT EXISTS `ls_user_administrator` (
  `user_id` int(11) unsigned NOT NULL,
  UNIQUE KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Member

jerald_rippin

by jerald_rippin , in category: SQL , a month ago
no answers

Is Number function in SQL 😚

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
create function is_numeric (
	@a varchar(100)
) returns int as begin
	declare @retval int
	set @a = replace(@a, '0', '')
	set @a = replace(@a, '1', '')
	set @a = replace(@a, '2', '')
	set @a = replace(@a, '3', '')
	set @a = replace(@a, '4', '')
	set @a = replace(@a, '5', '')
	set @a = replace(@a, '6', '')
	set @a = replace(@a, '7', '')
	set @a = replace(@a, '8', '')
	set @a = replace(@a, '9', '')
	set @a = replace(@a, '.', '')
	if len(rtrim(ltrim(@a))) > 0 set @retval = 0
	else set @retval = 1
	return @retval
end


Member

jerald_rippin

by jerald_rippin , in category: SQL , 2 months ago
no answers

Store Procedure in SQL not good example

1
2
3
4
5
if @SubDepartmentID = 0 set @SubDepartmentID = null
if @QuoteID = 0 set @QuoteID = null
if @PartnerID = 0 set @PartnerID = null
if @QuoteID = 0 set @QuoteID = null
if @SubDepartmentID = 0 set @SubDepartmentID = null